13

I wonder if it is valid C++ :

class Test {
    struct PrivateInner {
        PrivateInner(std::string const &str) {
            std::cout << str << "\n";
        }
    };

public:
    using PublicInner = PrivateInner;
};

//Test::PrivateInner priv("Hello world");        // Ok, private so we can't use that
Test::PublicInner publ("Hello World");           // ?, by using public alias we can access private type, is it ok ?
Johnmph
  • 3,391
  • 24
  • 32

1 Answers1

15

Types are neither public nor private. Access control only ever applies to names. Since PublicInner is a public name that refers to the PrivateInner class, it can be used outside the Test class.

Brian Bi
  • 111,498
  • 10
  • 176
  • 312