Like most of my questions, this one is an arbitrarily silly one.
How can I achieve what I'm trying to do? I'd like to avoid writing any constructor definitions in my header file.
//CTOR.H
#ifndef _CTOR_H_
#define _CTOR_H_
class OutSide {
public :
class Nested {
public :
Nested(int b);
Nested() {}; //Default ctor must be defined. Even if it is empty.
int a;
}nested; //It must be defined because you create an instance of it here using the default ctor.
OutSide();
};
#endif
//CTOR.CPP
#include "ctor.h"
OutSide::Nested::Nested(int b) {
a=b;
}
OutSide::OutSide() {
nested=Nested(10);
}
> The nested class needs to have a default constructor. Exactly what the error code says
No. The error says `you are trying to use something that doesn't exists'
1 2 3 4 5
OutSide::OutSide(): //starting the initialization list
nested(10) //specifying the constructor that you want
{ //members are already constructed here
//nested=Nested(10); //calling assignment operator
}