RAD Studio |  |

typename

Category

C++-Specific Keywords

Syntax 1

Copy Code

    typename identifier

Syntax 2

Copy Code

    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:
Copy 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)
Copy Code

    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)
Copy Code

    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) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!