class Foo {
// friend Bar;
public: const std::list<int*>& numbs () const { // (1)
return mNumbs;
}
protected: std::list<int*>& numbs () { // (2)
return mNumbs;
}
private: std::list<int*> mNumbs;
};
int main () {
Foo foo;
for (const auto& e : foo.numbs()) { // (3)
// some work...
}
}
My intention is to force to use (1) method for clients and (2) method for friends of Foo class. However compiler is trying to use (2) method that is protected in for statement and error is occured (3):
std::__cxx11::list<int*>& Foo::numbs()’ is protected within this context
I found some solutions:
- Changing name of (2) method (to numbs_ for example).
- Changing access class of (2) method to public (I'm not satisfied with that).
Does anyone know any better idea?