Private scope in locally-defined class

Viewed 85

Here's a small example that demonstrates my question:

class Foo {
private:
  int x;
  void y() {
    class Bar {
    public:
      Bar(Foo* foo) {
        foo->x = 3;
      }
    };
    Bar bar(this);
  }
};

Class Foo, and a class defined inside its member function y tries to access its private member x. Is this allowed?

Visual Studio 2013 can compile this, but IntelliSense seems to think that the private members cannot be accessed and does not list them when typing foo-> inside the embedded class methods.

1 Answers
Related