Hi everyone!
I want to access the Outer Class variables from the Inner Class, but I get an error (see below).
I have this code that illustrates what I'm trying to do:
.ino
class OuterClass{
public:
OuterClass(){}
void setup(char* Item){_item = Item;}
class InnerClass{
public:
InnerClass(int Index){_index = Index;}
int print() {Serial.println(_item[_index]);}
private:
int _index;
};
InnerClass item(int Index){}
private:
char* _item;
};
//-------------------------------
OuterClass class1;
char myItem[] = "One item";
void setup(){
Serial.begin(115200);
class1.setup((char*)myItem);
class1.item(1).print();
}
void loop(){}
I'm getting this error:
Class.ino: In member function 'int OuterClass::InnerClass::print()':
Class:16: error: invalid use of non-static data member 'OuterClass::_item'
Class:9: error: from this location
invalid use of non-static data member 'OuterClass::_item'
I tried to use a static class, friend class, declare it outside the Outer Class, but I get more and different errors.
How can I do this?