C
Coltrane
I am trying to compile some code from the "C++ Programming Language
Special Edition" book and I am getting compiler errors with Visual C+
+
and g++. The sample code is in appendix C, section C.13.
The code is as follows:
template<class T>
class X{
static T def_val;
static T* new_X(T a = def_val);
};
template<class T> T X<T>::def_val(0,0);
template<class T> T* X<T>::new_X(T a) {}
template<> int X<int>::def_val<int> = 0; /*line 10 */
template<> int* X<int>::new_X<int>(int i){} /* line 11 */
I get the following errors with Visual C++
Error error C2143: syntax error : missing ';' before
'<' line 10
Error error C2988: unrecognizable template declaration/
definition line 10
Error error C2059: syntax error :
'<' line 10
Error error C2143: syntax error : missing ';' before
'<' line 11
Error error C2470: 'X<T>::new_X' : looks like a function
definition,
but there is no parameter list; skipping apparent body line 11
Error error C2988: unrecognizable template declaration/
definition line 11
Error error C2059: syntax error :
'<' line 11
When I compile this with g++ I get:
templates.cpp:10: error: expected initializer before '<' token
templates.cpp:11: error: expected initializer before '<' token
can someone tell me what the problem is.
Is this a problem with the compiler or am I just messed up in the
head
(very possible)
thanks for the help
john
Special Edition" book and I am getting compiler errors with Visual C+
+
and g++. The sample code is in appendix C, section C.13.
The code is as follows:
template<class T>
class X{
static T def_val;
static T* new_X(T a = def_val);
};
template<class T> T X<T>::def_val(0,0);
template<class T> T* X<T>::new_X(T a) {}
template<> int X<int>::def_val<int> = 0; /*line 10 */
template<> int* X<int>::new_X<int>(int i){} /* line 11 */
I get the following errors with Visual C++
Error error C2143: syntax error : missing ';' before
'<' line 10
Error error C2988: unrecognizable template declaration/
definition line 10
Error error C2059: syntax error :
'<' line 10
Error error C2143: syntax error : missing ';' before
'<' line 11
Error error C2470: 'X<T>::new_X' : looks like a function
definition,
but there is no parameter list; skipping apparent body line 11
Error error C2988: unrecognizable template declaration/
definition line 11
Error error C2059: syntax error :
'<' line 11
When I compile this with g++ I get:
templates.cpp:10: error: expected initializer before '<' token
templates.cpp:11: error: expected initializer before '<' token
can someone tell me what the problem is.
Is this a problem with the compiler or am I just messed up in the
head
(very possible)
thanks for the help
john