The following code will cause C4624. But you can see D is not the sub class of B. Why still got this warning? Thanks!
class B {
// Uncomment the following line to resolve.
// public:
~B();
};
class D {B b;}; // C4624 B's destructor not public
More details about the warning:
C4624: ‘derived class’ : destructor could not be generated because a base class destructor is inaccessible
A destructor was not accessible in a base class and was therefore not generated for a derived class. Any attempt to create an object of this type on the stack will cause a compiler error.
Class members are initialised by the class’s constructor(s) and destroyed by its destructor. Their constructor(s) and destructor must therefore be accessible within those functions.
In your example,
Bhas a private destructor, and is therefore not accessible to the destructor ofD, which needs it to destroy its member of typeB.I’ve no idea why the error message refers to a “base class” though. If you get that error message from the code you posted, then your compiler could do with some improvements to its diagnostics.