RAD Studio |  |

Type Specifier decltype (C++0x)
Syntax | Examples | See Also
Collapse All

The C++0x standard includes the decltype keyword and operator, which represents the type of an expression. This feature is one of the C++0x features added to C++Builder 2009.

Syntax

The format of the decltype operator is:

Copy Code

    decltype ( expression )

Here are the rules for evaluating decltype(e):

- If e is an identifier expresson or accessing a class member, decltype(e) is the type of the thing designated by e. If there is no such thing, or if e is the name of a set of overloaded functions so there is ambiguity, decltype(e) is invalid.
- Otherwise, if e is a function call or invokes an overloaded operator, decltype(e) is the type returned by the function.
- Otherwise, if e is an lvalue, decltype(e) is a reference to T (T&) where T is the type of e.
- If none of the other cases apply, decltype(e) is the type of e.

Examples

See the embedded contents in the following examples.

Copy Code

    const char *namePtr, nameChar;
    decltype(namePtr);      // type is const char*
    decltype(nameChar);     // type is const char
    int& F(void);
    decltype(F());          // type is int&

    struct; D {double value; }
    const D* d = new D();

    decltype(d->value);    // type is double
    decltype((d->value));  // type is const double&

    double GetValue(int one);
    long int GetValue(double d);
    decltype(GetValue);     // ill-formed -- ambiguous

See Also

C++0x Features (C++Builder 2009)

Working Draft - Standard for Programming Language C++ (Sec. 7.1.6.2 - Simple Type Specifiers)

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!