Re: template error messages
Imre wrote:
Hi
Please consider the following, illegal code:
template <typename T>
struct S
{
void F() { T::F(); }
};
int _tmain(int argc, _TCHAR* argv[])
{
S<int> s;
// ...
s.F();
return 0;
}
Of course, it won't compile, since int::F() doesn't exist. My problem
is that the error message the compiler reports is not that helpful. It
only reports where S<int> is instantiated, but won't show where the
S<int>::F() call is,
Which version of the compiler are you using? Visual 2005 gives me :
error C2825: 'T': must be a class or namespace when followed by '::'
1> d:\users\adb\dev\temp\test_vc_2005\test_vc_2005.cpp(10) :
while compiling class template member function 'void S<T>::F(void)'
1> with
1> [
1> T=int
1> ]
1> d:\users\adb\dev\temp\test_vc_2005\test_vc_2005.cpp(16) : see
reference to class template instantiation 'S<T>' being compiled
1> with
1> [
1> T=int
1> ]
If I change sligthly your code so that "T" is a class :
int main()
{
S<std::string> s;
s.F();
return 0;
}
then I get another error message:
1>d:\users\adb\dev\temp\test_vc_2005\test_vc_2005.cpp(11) : error
C2039: 'F' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> d:\users\adb\dev\temp\test_vc_2005\test_vc_2005.cpp(11) :
while compiling class template member function 'void S<T>::F(void)'
1> with
1> [
1> T=std::string
1> ]
1> d:\users\adb\dev\temp\test_vc_2005\test_vc_2005.cpp(17) : see
reference to class template instantiation 'S<T>' being compiled
1> with
1> [
1> T=std::string
1> ]
Although those errors are quite (too) long, thay are quite clear (at
least for template related stuff....)
Arnaud
MVP - VC