I'm fiddling with template specialisation (it's been on my list of things to do for weeks) and found a little tutorial on cplusplus.com but MSVC 7.1 doesn't seem to like it:
Code:
template< typename T > class Container
{
public:
Container( T& val )
{
m_Value = val;
}
~Container()
{}
void Increment();
private:
T m_Value;
};
template< typename T > void Container< T >::Increment()
{
++m_Value;
}
// Specialisation of Container class
template<> class Container< char >
{
public:
Container( T& val )
{
m_Value = val;
}
~Container()
{}
void Uppercase();
private:
char m_Value;
};
template<> void Container< char >::Uppercase()
{
return toupper(m_Value);
}
Am I doing something wrong? I thought it was just MSVC 5 that didn't like this.
EDIT: The errors:
Code:
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(122) : error C2143: syntax error : missing ')' before '&'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(122) : error C2143: syntax error : missing ';' before '&'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(122) : error C2460: 'Container<char>::T' : uses 'Container<char>', which is being defined
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(134) : see declaration of 'Container<char>'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(122) : error C2059: syntax error : ')'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(122) : error C2501: 'Container<char>::val' : missing storage-class or type specifiers
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(124) : error C2065: 'val' : undeclared identifier
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(124) : error C2864: 'm_Value' : only const static integral data members can be initialized inside a class or struct
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(124) : error C2501: 'Container<char>::m_Value' : missing storage-class or type specifiers
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(127) : error C2588: '::~Container' : illegal global destructor
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(132) : error C2059: syntax error : 'private'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(134) : error C2059: syntax error : '}'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(134) : error C2143: syntax error : missing ';' before '}'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(134) : error C2059: syntax error : '}'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(136) : error C2143: syntax error : missing ';' before '<'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(136) : error C2182: 'Container' : illegal use of type 'void'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(136) : error C2373: 'Container' : redefinition; different type modifiers
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(127) : see declaration of 'Container'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(136) : error C2988: unrecognizable template declaration/definition
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(136) : error C2059: syntax error : '<'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(142) : error C2143: syntax error : missing ';' before '{'
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(142) : error C2447: '{' : missing function header (old-style formal list?)