RAD Studio
ContentsIndex
PreviousUpNext
typename

Category 

C++-Specific Keywords 

Syntax 1  

typename identifier

Syntax 2

template < typename identifier  > class identifier

Description 

Use the syntax 1 to reference a type that you have not yet defined. See example 1. 

Use syntax 2 in place of the class keyword in a template declaration. See example 2.

Note: When using the typename
keyword with templates, the compiler will not always report an error in cases where the ANSI standard requires the typename keyword. The compiler will flag the omission of typename when the compiler is invoked with the -A switch. For example, given the following code:

#include <stdio.h>
struct A{ typedef int AInt; };

Note: The compiler will flag the omission of typename when the compiler is invoked with the -A
switch.
Note: Compile with: bcc32 (no -A switch)

bc++bcc32 test.cpp

The result is no error. The Compiler should not assume AInt is a typename, but it does unless -A switch is used

Note: Compile with: bcc32 (-A
switch)

bc++bcc32 -A test.cpp

The result is: 

Error E2089 47071.cpp 7: Identifier 'AInt' cannot have a type qualifier 

Error E2303 47071.cpp 7: Type name expected 

Error E2139 47071.cpp 7: Declaration missing ; 

Both results are as expected.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!