Public 非 public 类型的别名

Public alias for non-public type

我想知道它是否是有效的 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 ?

类型既不是public也不是私有的。访问控制仅适用于 names。由于 PublicInner 是一个 public name 引用 PrivateInner class,它可以在 Test 之外使用class.