int main(int argc, char* argv[]) {
const int i = 10;
using Type = typename std::conditional<false, int, int&>::type;
const Type r = i; // It seems this 'const' does not have any effect.
std::cout << r << std::endl;
}
The above code cannot compile on gcc4.8.1 -std=c++11, and the error message goes as following: "invalid initialization of reference of type 'Type {aka int&}' from expression of type 'const int'. But, it will work if I change the code like this:
int main(int argc, char* argv[]) {
const int i = 10;
using Type = typename std::conditional<false, const int, const int&>::type;
Type r = i;
std::cout << r << std::endl;
}
Is there any body can show me the reason?