Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++CodeRAD Studio

Discover The C++ Declared Type of Expression Feature In Windows Development

Declared type of an expression is a feature supported by both BCC32 and the Clang-enhanced C++ compilers. The decltype type specifier is used to obtain the type specifier of an expression. This feature is one of the C++11 features.

decltype(expression) takes expression as an operand. When you define a variable by using decltype(expression), it can be thought of as being replaced by the compiler with the type or the derived type of expression. Consider the following example:

In this example, decltype(i) is equivalent to the type name int.

General rules for using decltype

  • If expression is an un-parenthesized id-expression or class member, decltype(expression) is the type of the entity named by expression. If there is no such entity, or if expression names a set of overloaded functions, the program is ill formed.
  • Otherwise, if expression is a function call or an invocation of an overloaded operator (parentheses around expression are ignored), decltype(expression) is the return type of the statically chosen function.
  • Otherwise, if expression is an lvalue, decltype(expression) is T&, where T is the type of expression.
  • Otherwise, decltype(expression) is the type of expression.


Here are the declarations of the structures and functions needed for the example, that should be placed in the header file:

Here is the source code:

Head over and check out all of the latest C++ features and declared type of expression for Windows development.

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Related posts

Quickly Deploy Powerful Internet Enabled Windows Apps With Clever Internet Suite For Delphi


Incredible Database Development And Visualization Tool Is Built In Delphi

C++CodeIDERAD Studio

Learn How To Use C++ Extending Sizeof For Windows Development

DelphiRAD Studio

Learn How Easy It Is To Apply Updates With TFDQuery.OnUpdateRecord In Delphi

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.