Public Group

# 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.

## 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 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 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 on other sites
Oh, and moved to For Beginners.

##### 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 on other sites
Forward declarations:
class two;class one{...    function(two &obj);};class two{...    other_function(one &obj);}

##### 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 on other sites
Thanks that works very well,

sorry for the n00b question :\$

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
16
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632593
• Total Posts
3007271

×