0

This code:

#include <iostream>

class Parent
{
  int name;
  class Child
  {
    int school;
    void test()
    {
      std::cout << this->name;
    }
  };
};

int main(int argc, char *argv[])
{
  Parent MyParent;
  
  return 0;
}

Generates this error:

error: 'class Parent::Child' has no member named 'name'

Is there any way to allow a nested class to access members of its parent?

I have some code with two classes, A and B, that were both referencing varaiables like global.value defined in a global variable called "global". I moved these variables into A and also made B a member of A, but found that B can't access A's members. Is there any way to do this without using 'static'?

Thanks,

Dave

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by HealBrains
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.