On 08/05/2014 at 20:07, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R14
Platform: Windows ;
Language(s) : C++ ;
---------
Hi folks,
just looking for a little bit of education here. I'm using static_cast to get data out of a void reference, like the following:
class_function(int id,void *link)
{
MyStruct_1 *mst_1 = NULL;
MyStruct_2 *mst_2 = NULL;
if(id == 1)
{
mst_1 = (MyStruct_1* )Link;
}
else if(id == 2)
{
mst_2 = (MyStruct_2* )Link;
}
// rest of code etc
}
As far as the function being called and working, everything seems fine with the above. But what I'm wanting to know is, is it possible to get the link type by testing it against the different struct types? Something like this:
class_function(void *link) // int id removed
{
MyStruct_1 *mst_1 = NULL;
MyStruct_2 *mst_2 = NULL;
if(link == static_cast<MyStruct_1*>(link))
{
mst_1 = (MyStruct_1* )Link;
}
else if(link == static_cast<MyStruct_2*>(link))
{
mst_2 = (MyStruct_2* )Link;
}
}
I know the above doesn't work, but it might help to illustrate what I'm getting at! Is it possible to test a static_cast's type with something like the above? Or will I have to use the additional "int id" argument to get/set it's type?
Cheers,
WP.
EDIT: further reading is suggesting that there's no particularly safe way of doing this, though I'd still be interested to hear from anyone who'd like to provide some thoughts.