I think something is wrong with the deconstructor but have no idea. In fact, I don't understand the usage of deconstructor. The code is like this
#include <iostream>
using namespace std;
class A
{
public:
explicit A(int x);
virtual ~A()=default;
protected:
int a;
void function1(int X);
};
class B:public A
{
public:
explicit B(int x);
~B();
private:
int c;
};
void A::function1(int X){
std::cout << "function1 " << X<< endl;
}
A::A(int x):a(0)
{
std::cout << "A " << x+a<< endl;
}
B::B(int x):A(x),c(3)
{
std::cout << "B " << x+c<< endl;
}
int main()
{
B b1(1);
return 0;
}
It shows
/home/qiuyilin/projects/inheritance/main.cpp:36: undefined reference to vtable for B'
CMakeFiles/inheritance.dir/main.cpp.o: In function
main':
/home/qiuyilin/projects/inheritance/main.cpp:43: undefined reference to `B::~B()'
collect2: error: ld returned 1 exit status