#include <iostream>
#include <typeinfo>
int main()
{
const char a[] = "hello world";
const char * p = "hello world";
auto x = "hello world";
if (typeid(x) == typeid(a))
std::cout << "It's an array!\n";
else if (typeid(x) == typeid(p))
std::cout << "It's a pointer!\n"; // this is printed
else
std::cout << "It's Superman!\n";
}
x
文字列リテラルが実際には配列であるのに、ポインタであると推定されるのはなぜですか?
ナロー文字列リテラルの型は「n
const char
の配列」 [2.14.5 文字列リテラル [lex.string] §8]