C
Chameleon
I know than dynamic_cast check string name of derived to base class and
if one of them match, return the pointer of that object or else zero.
I suppose, I dynamic_cast instead of strings, checks integers, then this
procedure will be more fast, so I create something like this:
---------------------------------------------
class A
{
public:
const static int RTTI = 0;
virtual bool checkRTTI(int rtti) { return RTTI == rtti; }
};
class B : public A
{
public:
const static int RTTI = 1;
virtual bool checkRTTI(int rtti) { return RTTI == rtti ||
A::checkRTTI(rtti); }
};
int main()
{
B b;
A *a = &b;
a->checkRTTI(B::RTTI);
return 0;
}
---------------------------------------------
I am curius why when I count the time to do this:
a->checkRTTI(B::RTTI)
I found it 5 times bigger than this:
dynamic_cast<B*>(a) ? true : false
I am offtopic? Compiler is mingw-g++
thanks!
if one of them match, return the pointer of that object or else zero.
I suppose, I dynamic_cast instead of strings, checks integers, then this
procedure will be more fast, so I create something like this:
---------------------------------------------
class A
{
public:
const static int RTTI = 0;
virtual bool checkRTTI(int rtti) { return RTTI == rtti; }
};
class B : public A
{
public:
const static int RTTI = 1;
virtual bool checkRTTI(int rtti) { return RTTI == rtti ||
A::checkRTTI(rtti); }
};
int main()
{
B b;
A *a = &b;
a->checkRTTI(B::RTTI);
return 0;
}
---------------------------------------------
I am curius why when I count the time to do this:
a->checkRTTI(B::RTTI)
I found it 5 times bigger than this:
dynamic_cast<B*>(a) ? true : false
I am offtopic? Compiler is mingw-g++
thanks!