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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With