Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   from void* back to an object (http://www.go4expert.com/forums/void-object-t6395/)

mad_girl 17Sep2007 18:52

from void* back to an object
 
now here's the problem
i'm trying to make a linked list store different types of data object (which i don know what they r now)
so i used void* like this
//for example a node of int
node<userDefindData>* n;
void* ptr=n;
and now i have the address of my node in my ptr ,but how can i treat this pointer as an object
and call its functions???????

shabbir 17Sep2007 20:29

Re: from void* back to an object
 
Make an object pointer and cast the void pointer to the object pointer and that should allow you to call the functions of that object.

mad_girl 17Sep2007 20:41

Re: from void* back to an object
 
firstly if i'm using node to store userDefinedData1, userDefinedData2, userDefinedData3 and i don know now which of them this pointer refering to so i can't make the cast..
secondly it gives me an error on a statement like this
node<userDefinedData>* k=dynamic_cast<node<userDefindData>*>(ptr);

shabbir 18Sep2007 09:11

Re: from void* back to an object
 
If you do not know what type of object it is you should also not know what function to call.


All times are GMT +5.5. The time now is 21:54.