Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

会员投稿 投稿指南 本期推荐:
搜索:
您的位置: Linux安全网 > Linux编程 > » 正文

VC6和VS2008中C++编译器差异

来源: 未知 分享至:

1. for中定义变量作用域不同

for (int i=0; i<100; i++){}
for (int i=100; i<200; i++){}

以上代码在VS2008中可编译通过;在VC6.0下会提示" 'i' : redefinition "的编译错误。

2. static const变量能否在头文件中初始化

class A
{
public:
	static const int m_MAXNUM = 10;
};

以上代码在VS2008中可编译通过;在VC6.0下会提示出两个令人费解的编译错误。

error C2258: illegal pure syntax, must be '= 0'

error C2252: 'm_MAXNUM' : pure specifier can only be specified for functions

将代码修改为以下即可通过编译

//a.h
class A
{
public:
	static const int m_MAXNUM;
};
// a.cpp
const int A::m_MAXNUM = 10;

 

这些差异是我们需要在移植代码时考虑的,紧记!


Tags:
分享至:
最新图文资讯
1 2 3 4 5 6
验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史