dynamic_cast to another base class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have follwoing situation.

class A;

class B : public A;

class C;

class D : public B,  public C

class E
{
   private:
       A* a;
public:
       A* getA ();

       E ()
{ a = new D (); } }

int main ()
{
   E e;

   A* a = e->getA ();

   C* c = dynamic_cast<C*> (a); // fails !!!
}


Why does dynamic_cast fail ??

Anyway I could actually dynamic_cast to first D* and then static cast to C*. But the problem is there could be D1, D2 etc. which all follow same hierarchy and I don't know exact class in main code.

Any suggestions are welcome.

Thanks in advance.

Regards,
Aseem.

--
If you are good, you will be assigned all the work.  If you are real good, you will get out of it



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux