Sign in to follow this  

C++ void** parse

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

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