Sign in to follow this  

void * * : having doubts

This topic is 4341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well a pointer is a means of redirection.
You need one level of redirection (void*) because when you create a COM object, you get an interface pointer which the factory method stores in the location that void pointer stores to.

HRESULT CreateStuff( void* pointer );

FunkyObject obj;
CreateStuff( (void*) &obj );
// stuff is created in location pointed to by pointer
obj.DoCoolThings();

Since you use interfaces in COM (because you need polymorphism), you don't get an object, but (a pointer) to an object (because pointers/references are needed for virtual function calls).
Thus, the factory method looks like this:

HRESULT CreateObjAndGetInterface( void** pointer_to_interface_pointer);
IFunkyInterface* iface;
CreateObjAndGetInterface( (void**) &iface );
// Create a pointer to the interface pointer in the specified location
iface->PolymorphicallyDoCoolThings();


I hope this makes sense. If not, let me know.

Share this post


Link to post
Share on other sites
In C, it is common to pass things by pointer so that the function can change the caller's data (normally a copy would be made of the thing being passed, so that only the copy can be affected, and then the copy disappears when the function ends and it goes out of scope). In C++ this is normally done by passing by reference instead. (In C++ it is also much less common to use void* at all, because it removes useful type information that could be preserved by C++'s more elaborate type system.) However, in C++ one must often deal with APIs that were written to support C, and DirectX is one of those.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
However, in C++ one must often deal with APIs that were written to support C, and DirectX is one of those.


I see..
I onli know C++
Now i can understand why i struggle with Directx at the beginning
So if i would to go back to study C, wat should i take notice?

And IS IT true that People who know C are much better programmer than those to starts off with just C++?

Share this post


Link to post
Share on other sites
Quote:
Original post by white-wolf
And IS IT true that People who know C are much better programmer than those to starts off with just C++?

No.

Share this post


Link to post
Share on other sites

This topic is 4341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this