Jump to content
  • Advertisement
Sign in to follow this  
_Camus_

C++ void** parse

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

Hi all, i want to use a function like this: function(void** thing); The goal is to pass any object i want: Ai* obj; obj = new obj[10]; function((VOID**)&obj); At this step all seems right, but in the function itself: function(void** thing) { thing[0].method(); } Here i dont know what to do, the compiler says: expression must have class type How i need to change this to work, i dont find how. I hope you can help me , Thanks!

Share this post


Link to post
Share on other sites
Advertisement
In C++ we avoid the void type. That is because it goes against the principle of type safety.

By casting a pointer of type MyObj* to void*, you lose all type information. The compiler is telling you that objects of type void do not define a function called "method()".

You want to use generics to solve this problem:


template<typename T>
void foo(T t)
{
t.method();
}

Share this post


Link to post
Share on other sites
Not necessarily; depending on the situation, virtual functions may be more suited to the task. But fpsgamer is right: void* is not to be used in C++ unless you know what you're doing. _Camus_, what precisely are you trying to accomplish?

Share this post


Link to post
Share on other sites
Thanks, the main problem is this:

class one
{
... //stuff

function(two obj);

};

class two
{
...//stuff

other_function(one obj);

};

if i include one i need to include the other, but in that case, both are
included xD and i cannot do that, thats why i try using void** to pass
whatever i want, but it seems more difficult than i thought.

The problem its that class one its the physx, and the class two its the
Ai so, i need to use physx to my Ai, but i need to calcule things of Ai
on physx, there its a way to deal ?
Thanks again

Share this post


Link to post
Share on other sites
For future reference, this is why you should always explain what you are trying to achieve, instead of just what you are doing.

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!