'Explaining output (inheritance, c++)

Consider the following program:

using namespace std;

class A{
    private:
        int _a;

    public:
        A(int a): _a(a) {cout<<"A-ctor: a= "<<_a<<endl;}
        A(const A& other) : _a(other._a) {
            cout<< " A-copy ctor: _a= " << _a<< endl;
        }
        ~A() {cout << "A-dtor" << endl;}
};

class B{
    private:
        A* _aPtr;
    public:
        B(int a=0) : _aPtr(new A(a)) { cout << "B-ctor"<<endl;}
        ~B() {cout<<"B-dot"<<endl; delete _aPtr;}
};

class C:public B{

    public:
        C(int a=5) : B(a) {cout<< "C-ctor"<<endl;}
        C(const C& other) : B(other) {cout<< "C-copy ctor"<<endl;}
        ~C() {cout<<"C-dtor"<<endl;}
};

int main()
{
    C c1;
    C c2(c1);
    return 0;
}

I would expect a compilation error since B does not have a copy-constructor and we try to use with C c2(c1)

But the actual output is:

A-ctor: a= 5
B-ctor
C-ctor
C-copy ctor
C-dtor
B-dot
A-dtor
C-dtor
B-dot
A-dtor

Why there is no compilation error here?

Thanks in advance.

c++


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source