


Why Does `decltype((...))` Return a Reference While `decltype(...)` Doesn\'t?
Nov 02, 2024 am 04:31 AMUnderstanding the Significance of Parentheses in decltype((...))
The use of double parentheses in decltype((...)) has a subtle but important impact on the type deduced by the decltype operator, as evidenced in the example from the C 17 Function Definition Concurrency (FCD).
When applied to an unparenthesized identifier (id-expression) or a class member access expression, decltype returns the type of the referenced entity. However, when the expression is an lvalue (a variable or expression referring to a memory location), decltype prefixes an additional reference (&) before the entity's type.
In the FCD example:
- decltype(a->x) references a member variable (double x) of a class instance (*a) and thus returns the base type of the member: double.
- decltype((a->x)) wraps the same member access expression within parentheses, treating it as an lvalue. As a result, decltype returns the type of the lvalue, which is a reference to the double type: const double&.
The above is the detailed content of Why Does `decltype((...))` Return a Reference While `decltype(...)` Doesn\'t?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the types of values returned by c language functions? What determines the return value?

C language function format letter case conversion steps

What are the definitions and calling rules of c language functions and what are the

Where is the return value of the c language function stored in memory?

How do I use algorithms from the STL (sort, find, transform, etc.) efficiently?

How does the C Standard Template Library (STL) work?
