int main() { const int a = 1; const int b = 2; typedef decltype(a*b) multiply_type; cout << typeid(multiply_type).name() << endl; return 0; }
The return value of the program is that multiply_type is an int. I'm very surprised. I expected the deduction type to give const int, and since the expression gives the value pr, the resulting type will be const int.
PS: with auto, the return value will be int when it discards the const qualifier.
Any ideas why multiply_type is int instead of const int with decltype?
Edit: Added an example of addition, which is also associated with the cv qualifier.
#include<iostream>
Edit 2: Check out our link. http://thbecker.net/articles/auto_and_decltype/section_07.html `
int x; const int& crx = x; / The type of (cx) is const int. Since (cx) is an lvalue,
source share