Should *(int*) be just int in C++11?
I run compile below code with g++ -std=c++11, it outputs "0", which is out of my expectation.
int num = 0;
int *num_ptr = #
cout<<std::is_same<decltype(num), decltype(*num_ptr)>::value<<endl;//0
Besides types, decltype also considers value categories.
For id-expression, i.e. num, decltype leads to its type which is int.
For *num_ptr, which is an lvalue-expression, decltype leads to T& i.e. int&.
If the argument is an unparenthesized id-expression or an unparenthesized class member access expression, then decltype yields the type of the entity named by this expression.
If the argument is any other expression of type T, and
a) if the value category of expression is xvalue, then decltype yields T&&;
b) if the value category of expression is lvalue, then decltype yields T&;
c) if the value category of expression is prvalue, then decltype yields T.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With