i have a CCArray, it contains some different type object as CCString, CCNumber, CCDictionary
so, i want to check the object type, i don’t known how to do it, anyone have a idea ?
Using dynamic_cast will return NULL if the object is not of the correct type.
thanks Lance Gray, that’s a good idea.
another way, i also want to enumerate a CCDictionary since i don’t known the object in it.
maybe it’s a hard job, or impossible.
i have try to use typeid, like below:
class Base
{
};
class Diverse : public Base
{
};
Base base = new Diverse;
std::cout<<typeid.name<<std::endl;
i think it should print like :P4Diverse, but it printP4Base*, i don’t known why…
This may help:
i got the way, the code should be like this
class Base
{
public:
virtual void fun( void )
{
std::cout<<"Base()\n";
}
};
class Diverse : public Base
{
public:
virtual void fun( void )
{
std::cout<<"DivXYZ()\n";
}
};
Base *base = new Diverse();
std::cout<
now it print: 7Diverse, the object type can be checked.
hope i can help someone like me .