Jump to content
  • Advertisement
Sign in to follow this  
white-wolf

void * * : having doubts

This topic is 4651 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

i am getting confused with void * and void **. it is a pointer to a pointer.. but how does this explain in DirectX? Or even any simple C++ theory.

Share this post


Link to post
Share on other sites
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!