Hi weaknessforcats ,
I have never mentioned the code can not compile. But it has type safety issues. You think the code I posted in my original question does not have any type safe issue, i.e. invoking CoCreateInstanc e directly?
regards,
George...
User Profile
Collapse
-
Hi oler1s,
Are there any practical benefits if we use extern keyword to qualify a variable defined in the same cpp file? This is my question.
regards,
George...Leave a comment:
-
Hi weaknessforcats ,
Maybe I have not made myself understood. My question is, if developed wants to get IID_IY and wrongly pass the pointer to IZ type, there will be no warning information, and the pointer to IZ interface will be wrongly pointed to a pointer to IY type, right?
So, in short, no type safety checking for IID and related type of interface pointer, right?
regards,...Leave a comment:
-
type safe issue
Hello everyone,
My question is whether my understanding of the solution to type safe issue in CoCreateInstanc e is correct. There is type safe issue in CoCreateInstanc e,
http://msdn2.microsoft .com/en-us/library/ms686615.aspx
STDAPI CoCreateInstanc e(
REFCLSID rclsid,
LPUNKNOWN pUnkOuter,
DWORD dwClsContext,
REFIID riid,
LPVOID * ppv
);
... -
Hi oler1s,
Why it is needed to use extern even if we are in the same cpp file? Any more description please?
(I think extern is useful for cross-compile unit cross-reference usage, if only in one compile unit, is it very helpful?)
regards,
George...Leave a comment:
-
Hi weaknessforcats ,
Any comments?
--------------------
Imagine this situation: object A holds a smart pointer to object B,
which in turn holds a smart pointer to object A. For whatever reason, A
decides to release its reference on B, by calling Release() on the smart
pointer. This happens to be the last reference, so B destroys itself. In
its destructor, it releases its reference...Leave a comment:
-
smart pointer release
Hello everyone,
About the release method implementation of smart pointer of COM, there are two approaches below, and approach 1 is preferred is recommended by Inside COM -- should be better.
Anyone know why approach 1 is better than approach 2?
(m_pI is interface pointer to a COM interface of type T, and it is a member variable of the COM smart pointer class)
Approach 1:
... -
Sure, RedSon.
Any comments to my post #13? I think to demonstrate the usage of extern, we should use more than one compile unit (cpp file) to demonstrate, right?
regards,
George...Leave a comment:
-
Hi RedSon,
I do not think the same in the MSDN page is good enough. When demonstrating extern, it should use more than one cpp files (more than one compile unit) right?
Code:// specifying_linkage1.cpp int i = 1; void other(); int main() { // Reference to i, defined above: extern int i; } void other() { // Address of global i assigned
Leave a comment:
-
Thanks weaknessforcats ,
I think we should add extern "C" to both declaration and definition, right?
http://www.glenmccl.co m/ansi028.htm
regards,
George...Leave a comment:
-
Hi hdanw,
Why in your below code,
pb->foo();
will output Final other than output Base? I have tested that the output is Final.
My question is
1. pb points Final instance, and the foo in Final is not virtual method;
2. so the output should be invoking the foo based on the type of pointer (which is Base), then the output should be Base?
regards,...Leave a comment:
-
Thanks hdanw,
Please review whether I am correct.
1. We should add extern to declaration, so what we know we are referring a function/variale from other compile unit;
2. We should also add extern to definition so that this function/variale is visible to other compile unit. In this case, extern is on the other side of static.
Right?
regards,
George...Leave a comment:
-
Thanks RedSon,
I am using Visual Studio 2008 to develop C/C++. Any advice about whether to add extern "C" to declaration only or both declaration and definition?
regards,
George...Leave a comment:
-
Thanks Dan,
Which API or sample do you think could be used for me to learn how to lock some memory pages?
I am interested in this topic. :-)
regards,
George...Leave a comment:
-
Hi hdanw,
Great reply! But I am not 100 sure about your samples.
In your below description, the code,
Base dp = (p);
should not compile not because of ambiguity issue, but syntax issue (left side object type, right side pointer type)
"We can shut the compiler up " -- what your compiler errors?
Again, it is appreciated if you could post your...Leave a comment:
-
Thanks Dan,
Does it mean hard page fault in your described situation below?
regards,
George...Leave a comment:
-
Hi Dan,
Can you show your completed code for how do you get the output,
--------------------
Final
Final
Final
--------------------
I can not understand how you make the pointer to Base pointing to the function table of Final?
regards,
George...Leave a comment:
-
Thanks RedSon!
Any comments to my post #4?
regards,
George...Leave a comment:
-
Sure, weaknessforcats . Used for stopping mangling name for function and variable, any comments to my original question?
regards,
George...Leave a comment:
-
extern "C"
Hello everyone,
Just to confirm what is the most correct way beyond a just working function.
1.
We need to add extern "C" to both variable/function definition/declaration? Or only need to add to the variable/function declaration?
2.
How about extern? Declaration only or both declaration and definition are required?
BTW: previously, I only add...
No activity results to display
Show More
Leave a comment: