I have a class (User
in the example below) that derives from a base class (Base
), passing a third class type (Used
) and a member pointer within that class as template parameters to the base class.
What do I need to do within Used
(i.e., what do I need to befriend) such that the pointed to data member can be private?
class User;
template <typename T, int T::*member>
class Base {
};
class Used {
// Befriend everything there is.
friend class User;
template <typename T, int T::*member> friend class Base;
// The variable that should be accessible.
int i;
};
// error: ‘int Used::i’ is private
class User : public Base<Used, &Used::i> {
};
(Not) working example on Ideone
Edit: Given that this seems to work on newer versions of GCC, how can I work around the problem given g++ 4.8.4?