Had a complicated program that kept throwing up the missing default constructor error, and after much tinkering, i found the exact same scenario that gives the same error. What’s wrong with this?
class B;
class A
{
public:
A() {instance = new B;}
virtual ~A() {delete instance;}
private:
A*instance;
};
class B : public A
{
public:
B(){}
}
can’t forward declare a derived class to be used within the base class?
How can
new Bsucceed if the compiler doesn’t know anything about classByet? If you move the member function implementations out of classAbelow the definition of classB, it should work:What exactly are A and B, anyway? Having a base class instantiate a derived class sure is a bit unusual.