Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 04-13-2004, 12:57 PM   #1 (permalink)
 
KnifeMissile's Avatar
 
Location: Waterloo, Ontario
[C++] Why do I need the typename keyword?

I'm trying to port code from VC.net to VC.net 2003. Here's a typical piece of code that's often used:
Code:
template<class T> class PseudoContainer {&#10&#9typedef T::iterator iterator;  // this line will change in the next example...&#10};
This compiles just fine under VC.net but it will not compile under VC.net 2003. In order to get this to compile with the new compiler, I need to add the typename keyword, like so:
Code:
template<class T> class PseudoContainer {&#10&#9typedef typename T::iterator iterator;  // this line was changed from the previous example...&#10};
Now, I can actually understand why you need the typename keyword. It's because the compiler can't tell if T::iterator is a type or a static member of T. Thus, you must tell it with the typename keyword. However, if that's the case, then why did it compile just fine under VC.net?

Any insight into this will be greatly appreciated!
KnifeMissile is offline  
Old 04-13-2004, 03:06 PM   #2 (permalink)
Wehret Den Anfängen!
 
Location: Ontario, Canada
VC6's template compiler is implemented almost like a macro. I can get some crazy shit to work that shouldn't under VC6... The parsing done by VC6 to a template is very minimal before it is instantiated. (I could be on crack, but this theory is consistent with the poking around I've done with templates)

When they did VC.net, they implemented a 'real' template compiler. Along the way, they ended up parsing more of the contents of a template. Which means they needed to know of a token was a type or a constant.
__________________
Last edited by JHVH : 10-29-4004 BC at 09:00 PM. Reason: Time for a rest.
Yakk is offline  
 

Tags
keyword, typename


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 11:04 AM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38