Why do I keep on getting the following error in this code in Visual C++ 2010, and how do I fix it while maintaining the type inference capability for the member variable?
error C2825:
'Foo<T>::value_type':must be a class or namespace when followed by'::'
template<class T>
struct Foo
{
typedef typename T::value_type value_type;
template<class M>
void foo(M value_type::*member) const; // error
};
struct S { typedef int value_type; };
int main() { Foo<S> s; }
The template parameter
Tturns out to be typeS, thereforevalue_typeturns out to beint(the nested-type inS). So how can you writevalue_type::*member? Note that it turns out to beint::*memberwhich doesn’t make sense.intis not a class type.I think you meant
T::*memberinstead ofvalue_type::*member.