#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]