View Single Post
Old 04-13-2004, 12:57 PM   #1 (permalink)
KnifeMissile
 
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  
 

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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76