M
Maurice Termeer
Hi, suppose i've got this:
class a {
public:
int n;
};
class b : public a {
public:
};
and I next do this:
a *x = new b();
b *y = dynamic_cast<b *>(x);
If I compile this, the compiler (msvc++ 2005) says:
error C2683: 'dynamic_cast' : 'a' is not a polymorphic type
and gnu g++ 3.2.3 says:
cannot dynamic_cast `x' (of type `class a*') to type `class b*' (
source type is not polymorphic)
I don't understand this. Why can't I dynamically cast a pointer of type
base class to some derived class? Probably I have to tell the compiler
that class a has some subclasses. Anyone got an idea?
Maurice Termeer
class a {
public:
int n;
};
class b : public a {
public:
};
and I next do this:
a *x = new b();
b *y = dynamic_cast<b *>(x);
If I compile this, the compiler (msvc++ 2005) says:
error C2683: 'dynamic_cast' : 'a' is not a polymorphic type
and gnu g++ 3.2.3 says:
cannot dynamic_cast `x' (of type `class a*') to type `class b*' (
source type is not polymorphic)
I don't understand this. Why can't I dynamically cast a pointer of type
base class to some derived class? Probably I have to tell the compiler
that class a has some subclasses. Anyone got an idea?
Maurice Termeer