Solved

compiling templates in VC++ 5.0

Posted on 1997-04-22
4
388 Views
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
one.
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>;
39:
40:    public:
41:      NILNode_c();
42:
43:    private:
44:        T           Data;
45:        NILNode_c   *Next,
46:                    *Back;
47:};

--------------------Configuration: dtwin - Win32 Debug--------------------
Compiling...
DT_DLL.CPP
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)
0
Comment
Question by:mkhare
  • 2
  • 2
4 Comments
 

Expert Comment

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

Author Comment

by:mkhare
ID: 1162901
Edited text of question
0
 

Accepted Solution

by:
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
0
 

Author Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now