Why do I get
Error C2597: Illegal reference to non-static member
'derived<<unnamed-symbol>>::T'
when I try to compile this code in Visual C++ 2010 x64? (It seems fine on x86… which one is correct?)
struct base { typedef int T; };
template<class>
struct derived : base
{
using base::T;
derived(T = T()) { }
};
int main()
{
derived<int>();
return 0;
}
As Praetorian’s comment mentions, the problem is with the
T()default value. Based on the error details,using base::Tapparently confuses the compiler into searching forT()as a call to non-static member function ofbaserather than the construction of an instance of typeT.Here’s an interesting fix that works in MSVC 2005 x86 (I haven’t tried any other compiler). Note that
T()is preserved. This either disambiguatesusing base::Tor just forcesTto reference the inherited type and not theusingone (which are apparently not the same thing to the compiler).Edit: Try changing
baseto this and see what error messages you get:I get the original
C2597, but also this:I don’t know what the compiler means by
''there, but it’s probably a similar problem with the original definition ofbase. This compiles fine if I remove theusing base::T;line.