I have a class A, that is an abstract base class.(C++). Now, I have two classes B and C which inherit from A;
I have a virtual destructor in A;
The constructor in class A is protected.
Now, in the constructors of B and C, I have included a call to A’s constructor.
B::B():A()
{
//do something
}
similarly for C
C::C():A()
{
//do something
}
Now, while compiling I’m getting linking errors.
B.obj : error LNK2019: unresolved external symbol "protected: __
thiscall A::A(void)" (??0A) referenced in function "protected: __thiscall B::B(void)" (??0B)
C.obj : error LNK2001: unresolved external symbol "protected:
__thiscall A::A(void)" (??0A@XZ)
Error.
Please suggest how to resolve this.
Thanks,
Karhtik.
Firstly, there’s really no need to “call” the base class constructor explicitly. The default constructor of the base class will be called for you automatically.
Secondly, as @DeadMG already noted, the error you are getting suggests that you explicitly declared the
A::A()constructor, but forgot to define it.