#include <iostream>
#include <string>
using std::cout;
using std::endl;
int main()
{
typedef char* PCHAR;
static const PCHAR test1 = "Hello World";
PCHAR test2 = test1;
cout << "test1: " << test1 << endl;
cout << "test2: " << test2 << endl;
return 0;
}
此代码有效,但是当将test1和test2声明为char *而不是PCHAR时,出现以下错误:
In function 'int main()': 11:19: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
我不太清楚为什么显式说明类型会给我一个错误。任何帮助将不胜感激。