Template help,To Alexandre Oliva

Shiv Shankar Ramakrishnan Shiv@pspl.co.in
Mon Nov 13 21:07:00 GMT 2000


|> #if _MSC_VER >= 1200 //check for the version of your compiler
|> 	#define TYPENAME_ typedef
|> #else
|> 	#define TYPENAME_ typename
|> #endif
|
|This is wrong.  `typename' is not a replacement for `typedef'.  In
|this case, one must use typedef, because a type alias is what the
|declaration is going to define, and typename, because it must precede
|any template-dependent nested-name-specifiers that are supposed to be
|typenames regardless of the template arguments used in an
|instantiation.

Oops! You are right. I just shot that off in a hurry. My mistake. Yes a
typedef needs to precede the declaration in the typename case also.
What was I thinking? I guess these things sometimes get tricky and one
can miss out things :( (Esp. is you have used the older way)

So yes it should be -

#if _MSC_VER >= 1200 //check for the version of your compiler
	#define TYPENAME_
#else
	#define TYPENAME_ typename
#endif

And so the use as you pointed becomes -

typedef TYPENAME_ T1::Type1 Type1;


|Note that there are other uses of the typename keyword, such as in
|template parameters, that should either remain unchanged or be
|substituted with the `class' keyword.

Yes. Except that I assumed that the code (being older style) would not
use typename in template parameters. And yes in the other case its
better to change all template parameter uses of typename to the 'class'
keyword than use another ugly macro.

My apologies for causing all the confusion.
Thanks,
Shiv


More information about the Gcc mailing list