This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

dynamic_cast to another base class


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]