Reputation: 303
Recently, I stumbled on another C++ problem that gives me quite some hard time. Suppose we have the small program:
class A {
public:
virtual bool c() = 0;
virtual bool b() = { return false; };
virtual ~A() {}
}
class B : public A {
public:
bool b() = { return true; };
~B() {}
}
...
void c(A *pointer) {
if (pointer->b()) {
cout << "Derived class";
}
}
In this case, the compiler returns error on the "if" line of the method c() with the error "member access into the incomplete type A". Can somebody explain me why the compiler is returning such error? And if it is indeed right in firing an exception, then how can I prevent it?
Thanks very much!
Upvotes: 1
Views: 197
Reputation: 254461
"Incomplete type A
" means that in the code you're compiling (but not the code you posted), there isn't a definition of A
before it's used in c
. You will need the definition either in the same source file as c
, or in a header included from that source file.
Upvotes: 3