class C1
{
public:
C1* A;
void SomeMethod()
{
class C2;
C2* c2 = dynamic_cast<C2*>(A);
}
};
class C2 : public C1 {};
In gcc i'm getting "target is not a pointer or reference to complete type" when dynamic_cast is invoked. What's wrong?
The following compiles:
class C2;
class C1
{
virtual ~C1() { } // <--- NOTE MUST BE polymorphic to use dynamic_cast
public:
C1* A;
void SomeMethod();
};
class C2 : public C1 {};
void C1::SomeMethod()
{
C2* c2 = dynamic_cast<C2*>(A); // <=== USED after C2 definition
}
int main() {
}
Two problems: