Access Outer Class variables from Inner Class

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?

Nested classes cause all kinds of issues. Why do you insist on doing that?

Why can't the two classes be defined at the same level?

I want to access in a structure like this:

class1.item(1).print();

If I defined in the same level, I would have to declare it. The way above is more pratical.

And now I'm trying to make this work, as it's a good knowledge.

But if it there difficult problems, I will think in another method.

If I defined in the same level, I would have to declare it.

So? Why is that a problem?

I've stared at your code for a while now, and can't work out what you are doing.

What are you attempting to do here?