zoukankan      html  css  js  c++  java
  • 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;
    

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

  • 相关阅读:
    linux 时间同步
    sublime3 install python3
    Postfix的工作原理
    MySQL启动报错
    Socket server
    自定义静态网卡配置
    Nginx 404 500
    Pymysql
    Gitlab smtp 设置
    Windows 文件自动同步共享工具
  • 原文地址:https://www.cnblogs.com/kekec/p/2254051.html
Copyright © 2011-2022 走看看