Qt 5.1 编译中处理《error C2059: 语法错误:“常量”》错误

新装了VS2013的环境,由于是64位系统并且Qt对VS2013支持不好,需要自己编译一下,但是编译过程中出现了些坑爹的问题:

error C2059: 语法错误:“常量”

报错的文件是win-math.h,代码如下:

enum {
  FP_NAN,
  FP_INFINITE,
  FP_ZERO,
  FP_SUBNORMAL,
  FP_NORMAL,
};

这段代码毫无疑问没有任何问题,但是FP_NAN这个宏可就有问题了,
FP_NAN在VS2013的标准头文件math.h被定义成了
#define _NANCODE 2
#define FP_NAN _NANCODE

结果这段代码就变成了:

enum{
  2,
  FP_INFINITE,
  FP_ZERO,
  FP_SUBNORMAL,
  FP_NORMAL,
};

其他几个枚举值也有同样的问题,解决方法有两个:
一是删除这个枚举,毕竟在math.h中已有定义。
二是使用#undef:

#undef FP_NAN
#undef FP_INFINITE
#undef FP_ZERO
#undef FP_SUBNORMAL
#undef FP_NORMAL
enum FP_MATH_{
	FP_NAN,
	FP_INFINITE,
	FP_ZERO,
	FP_SUBNORMAL,
	FP_NORMAL,
};

这篇文章有 3 个评论

  1. 网事如风

    果然如此,谢谢博主
    VS2013改动还是比较大的,原来很多不符合标准的地方都改了,反倒让很多代码不适应他了

  2. Darin

    Even great players take time to get used to each other and you are
    unlikely to get top performances from new signings until they
    have settled in. This might be because of the fantastic gameplay and gaming
    experience it gives to its users. If you’re thinking that this ‘great’ football player sounds almost super-human,
    you’re not very far off the mark.

  3. expresowe włumaczenia

    If you wish for to grow your knowledge only
    keep visiting this site and be updated with the most up-to-date
    news posted here.

发表回复