class Settings
{
private:
typedef std::map<std::string, SettingsOption> OptionMap;
public:
typedef OptionMap::iterator iterator;
typedef OptionMap::const_iterator const_iterator;
...
};
Is this code portable? What does the standard state about it?
It's legal and Settings::iterator
and Settings::const_iterator
are accessible to all users of the Settings
class.
Access control in C++ is applied purely to names. There's a note and example in ISO/IEC 14882:2011 11 [class.access]/4 that makes it clear that this is the intention.
[...] [ Note: Because access control applies to names, if access control is applied to a typedef name, only the accessibility of the typedef name itself is considered. The accessibility of the entity referred to by the typedef is not considered. For example,
class A {
class B { };
public:
typedef B BB;
};
void f() {
A::BB x; // OK, typedef name A::BB is public
A::B y; // access error, A::B is private
}
—end note ]
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