Let's suppose I have something like:
class A
{
public:
A(A* owner)
{
m_owner=owner;
if (dynamic_cast<B*>(this))
{
m_id=sm_bid;
sm_bid++;
}
else
{
m_id=sm_aid;
sm_aid++;
}
}
private:
int m_id;
A* m_owner;
static int sm_aid;
static int sm_bid;
};
A::sm_aid=0;
A::sm_bid=0;
class B: public A
{
B(A* owner) : A(owner) {}
};
Unfortunately, the dynamic_cast is unable to catch that it is a B object (when instantiated). This sound logical (since the constructor in the superclass is called before to call the constructor in the subclass. Is there a way to achieve such functionality?