#include <iostream>
struct A
{
A() = delete;
A(int x)
: x(x)
{
}
virtual ~A() = 0;
int x;
};
A::~A() = default;
struct B : virtual A
{
B()
//: A(-1)
{
}
virtual ~B() = 0;
};
B::~B() = default;
struct C : B
{
C()
: A(7)
, B()
{
}
};
int main()
{
C c;
std::cout << c.x << std::endl;
}
prog.cpp: In constructor ‘B::B()’:
prog.cpp:19:2: error: use of deleted function ‘A::A()’
{
^
prog.cpp:5:2: error: declared here
A() = delete;
^
The program fails to compile because the constructor for B is malformed for not calling A::A(int). But why does it need to if B is abstract? Whatever constructor from A I call in B will always get ignored, right? Is there any reason not to allow the program to compile?
EDIT: Modified working program: http://ideone.com/N7py90
Note the call A(-1) will never be used.
> Whatever constructor from A I call in B will always get ignored, right?
Right.
[Note: An abstract class is never a most derived class, thus its constructors never initialize virtual base classes, therefore the corresponding mem-initializers may be omitted. —end note] - IS
> Is there any reason not to allow the program to compile?
The compiler may not be conforming wrt this.
With LLVM/clang++ this compiles cleanly.
With GNU/g++ or Mirosoft C++, it does not.