473,480 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

using template

the following codes can pass the compilation in VC6 but not in VC7.1..

is it a bug?

#include <list>

template<class type>
class myclass
{
typedef myclass<type> mytype;
std::list<mytype *>::iterator myit;
}
Nov 17 '05 #1
2 1262
"booker" <hu**********@kingsoft.net> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
the following codes can pass the compilation in VC6 but not in VC7.1..

is it a bug?

#include <list>

template<class type>
class myclass
{
typedef myclass<type> mytype;
std::list<mytype *>::iterator myit;
}


The error message is correct; it's not a compiler bug.
Whenever you use a type that's a member of a class
that's dependent on a template parameter, you have to
prefix it with "typename". Here, "std::list<mytype*>"
depends on what "type" is. There's no way for the
compiler to know, at the point when it's processing the
definition of the "myclass" template, whether
std::list<myclass<type>*> will even have an "iterator"
member, much less whether that member will be a type or
not, because it doesn't know what "type" will be. For
example, if you have "myclass<X>", someone might have
created an explicit specialization of
std::list<myclass<X>*> that does not declare a member
"iterator", or that declares it to be a data member
rather than a type.

Because the compiler has to know whether a given name
is a type or not in order to parse the code, you have to
tell it that you expect the name you're using to be a
type when the template is eventually instantiated. So,
the line in question should read

typename std::list<mytype*>::iterator myit;

vc++ 6.0 did not enforce this requirement. VC++ 7.1 does
a more thorough job of parsing template definitions and
thus is able to detect the error.

-- William M. Miller
Nov 17 '05 #2
i got it......
i used c++ for ten years and never know of this....

thank you very much...

"William M. Miller" <wm*@world.std.com> дÈëÓʼþ
news:bs************@ID-166721.news.uni-berlin.de...
"booker" <hu**********@kingsoft.net> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
the following codes can pass the compilation in VC6 but not in VC7.1..

is it a bug?

#include <list>

template<class type>
class myclass
{
typedef myclass<type> mytype;
std::list<mytype *>::iterator myit;
}


The error message is correct; it's not a compiler bug.
Whenever you use a type that's a member of a class
that's dependent on a template parameter, you have to
prefix it with "typename". Here, "std::list<mytype*>"
depends on what "type" is. There's no way for the
compiler to know, at the point when it's processing the
definition of the "myclass" template, whether
std::list<myclass<type>*> will even have an "iterator"
member, much less whether that member will be a type or
not, because it doesn't know what "type" will be. For
example, if you have "myclass<X>", someone might have
created an explicit specialization of
std::list<myclass<X>*> that does not declare a member
"iterator", or that declares it to be a data member
rather than a type.

Because the compiler has to know whether a given name
is a type or not in order to parse the code, you have to
tell it that you expect the name you're using to be a
type when the template is eventually instantiated. So,
the line in question should read

typename std::list<mytype*>::iterator myit;

vc++ 6.0 did not enforce this requirement. VC++ 7.1 does
a more thorough job of parsing template definitions and
thus is able to detect the error.

-- William M. Miller

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5923
by: Sam | last post by:
I would like to store html templates in a database. By using perl I would like to retrive the template ask the user to fill the template and store the whole file is template + the user data in a...
2
3379
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
4
3428
by: Pat Turner | last post by:
Hi, I have some XML like this: <family> <person name="bob"> <father ref="../../person" /> </person> <person name="charlie"> <child ref="../../person" />
2
2176
by: Sylvia | last post by:
Hi, I'm trying to render a XML structure to HTML using XSLT. My XML describe the header of a table with a complex and not linear structure. The first row of the header table always contains the...
4
319
by: Alexis | last post by:
Hi, I need to transform one xml document into a second xml document. They both have many nodes so xslt works fine, but there is one node I have not figure out how to transform. Here it is:...
3
2059
by: 胡岳偉(Yueh-Wei Hu) | last post by:
Hi all, I have 2 questions about template function as friends in template classes. I don't know why, and hope someone could help me. ...
0
1678
by: Yueh-Wei Hu | last post by:
Victor Bazarov <v.Abazarov@comAcast.net> wrote in message news: ============================================================== > > Question 1: > >...
8
4355
by: Douglas | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hello, The following code does not compile if line 3 is uncommented "using namespace std". I do not understand it. Could...
3
2365
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central...
5
2567
by: Gianni Mariani | last post by:
I'm hoping someone can tell me why using member address of works and why using the dot operator does not in the code below. The code below uses the template function resolution mechanism to...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7032
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6730
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4767
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.