【发布时间】:2018-05-11 07:48:30
【问题描述】:
我已经定义了一个这样的类型:
typedef char sType[256];
还有一个函数,带有默认参数:
void foo(const sType param = NULL);
MinGW (g++ 4.8.0) 编译它没有错误。
相反,Visual Studio 2015 (Tools 14.0) 给出以下错误:
error C2040: 'sType': 'int' differs in levels of indirection from 'char [256]'
我尝试将NULL 转换为const char[],但这会导致:
error C2440: 'type cast': cannot convert from 'int' to 'const char []'
有什么提示吗?谢谢
【问题讨论】:
-
尝试使用
nullptr,而不是NULL(另外,将旧的损坏编译器更新为现代编译器mingw-w64.org/doku.php)。 -
我收到
error C2065: 'nullptr': undeclared identifier。尝试了this(nullptr仿真),但我得到了其他错误。 -
您使用的是古老的 c++11 之前的编译器,所以这不足为奇。
-
VS2015 应该足够新才能知道 c++11 和 nullptr.....
-
似乎是一个 MSVC 错误。如果您改用
(char *)NULL,它是否有效。 (顺便说一句,如果你不知道,const sType在这种情况下是指char * const而不是const char *)
标签: c++ visual-studio visual-studio-2015 compiler-errors