I have a nested class and I would like it to have access to the attributes of the outer class. I've seen this done on other SO topics (here and some others). However, they always give a reference to an object of the outer class to be able to do that. In my particular case, I would like to avoid using a reference and do it like that:
class OuterClass {
private:
int _outerData;
public:
OuterClass(int data) : _outerData(data) {}
class InnerClass {
public:
InnerClass(){
// Modify or access outerData in the constructor or other methods
// without using InnerClass(OuterClass& OuterObj)
}
//Other methods
};
I want to do it like that because in my code the user has access to this using a method like this:
OuterClass::InnerClass* OuterClass::NewInnerClass("I don't want to pass any input in here") {
return new InnerClass("Input here is ok");
}
As you can see, I want the user to call the method without calling any arguments in order to be easier to use.
How can I achieve this type of behavior?