0

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.

Pavan Dittakavi
  • 3,013
  • 5
  • 27
  • 47

2 Answers2

0

This suggests that you never defined the default constructor of A when you declared it.

Puppy
  • 144,682
  • 38
  • 256
  • 465
  • @user815961: If it was "in place", you wouldn't be getting these linker errors. No, the constructor definition is not "in place" (whatever you mean by that "in place") – AnT stands with Russia Aug 01 '11 at 17:57
  • Hi all, actually, the abstract base class (A) has a constructor. And removing it from that abstract base class and all its child's (B & C) is resolving the issue. Is it that an abstract base class cannot have a constructor? http://stackoverflow.com/questions/1057221/what-are-practical-uses-of-a-protected-constructor – Pavan Dittakavi Aug 02 '11 at 04:25
0

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.

AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765