compiling templates in VC++ 5.0

Posted on 1997-04-22
Last Modified: 2008-03-06
I get a syntax error compiling the following template in
VC++ 5.0. The code is the winsock sdk code available from
microsoft. The code compiled under the old developer studio.
I could not find any option to get it compiled in the new
I add line numbers to the code:

36:template<class T> class NILNode_c {
37:    friend class NIDeque_c<T>;
38:    friend class NIDequeIter_c<T>;
40:    public:
41:      NILNode_c();
43:    private:
44:        T           Data;
45:        NILNode_c   *Next,
46:                    *Back;

--------------------Configuration: dtwin - Win32 Debug--------------------
C:\winsock\SAMPLES\DT_DLL\dtwin\nideque.h(37) : error C2059: syntax error : '<'
C:\winsock\SAMPLES\DT_DLL\dtwin\nideque.h(37) : error C2238: unexpected token(s) preceding ';'
C:\winsock\SAMPLES\DT_DLL\dtwin\nideque.h(38) : error C2059: syntax error : '<'
C:\winsock\SAMPLES\DT_DLL\dtwin\nideque.h(38) : error C2238: unexpected token(s) preceding ';'
C:\winsock\SAMPLES\DT_DLL\dtwin\nideque.h(69) : error C2989: 'NIDeque_c' : template class has already been defined as a non-template class
C:\winsock\SAMPLES\DT_DLL\dtwin\nideque.h(114) : error C2059: syntax error : '<'
C:\winsock\SAMPLES\DT_DLL\dtwin\nideque.h(141) : error C2588: '::~NIDeque_c' : illegal global destructor
C:\winsock\SAMPLES\DT_DLL\dtwin\nideque.h(141) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.

dtwin.dll - 8 error(s), 0 warning(s)
Question by:mkhare
  • 2
  • 2

Expert Comment

ID: 1162900
Please, mark what line is #37 ?

Author Comment

ID: 1162901
Edited text of question

Accepted Solution

snemanov earned 50 total points
ID: 1162902
Formally, friend class X; is not a class declaration.There was some disorder with it in the previous compiler versions.MSVC++ 5.0 has more strong approach to types declaration,so you should define NIDeque_c and NIDequeIter_c classes as template classes before NILNode_c class.Addtemplate<class T> class NIDeque_c;
template<class T> class NIDequeIter_c;
lines before the line #36 or include an appropriate header file.Feel free to ask additional questions if any.Regards, Sergey

Author Comment

ID: 1162903
i have compiled the code successfully using your suggestion

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question