It seems that a protected member from a template policy class is inaccessible, even with a class hierarchy which seems correct.
For instance, with the following code snippet :
#include <iostream> using namespace std; template <class T> class A { protected: T value; T getValue() { return value; } public: A(T value) { this->value = value; } }; template <class T, template <class U> class A> class B : protected A<T> { public: B() : A<T>(0) { /* Fake value */ } void print(A<T>& input) { cout << input.getValue() << endl; } }; int main(int argc, char *argv[]) { B<int, A> b; A<int> a(42); b.print(a); } The compiler (clang on OS X, but gcc returns the same type of error) returns the following error :
Untitled.cpp:18:21: error: 'getValue' is a protected member of 'A<int>' cout << input.getValue() << endl; ^ Untitled.cpp:25:5: note: in instantiation of member function 'B<int, A>::print' requested here b.print(a); ^ Untitled.cpp:8:7: note: can only access this member on an object of type 'B<int, A>' T getValue() { return value; } ^ 1 error generated. The strange thing is that the last note from the compiler is totally correct but already applied since the b object is of type 'B<int, A>'. Is that a compiler bug or is there a problem in the code ?
Thanks