再谈从vc6迁移到vs2005

   作为C++编译器,从vc6到vc8最大的调整就是对C++标准的支持更好了。
   我发现的几点不同。
a. For 循环的声明
      Vc6: for(int i<0;i<100;++i){}; j = i; (ok)

Vc8: for(int i<0;i<100;++i){}; j = i; (illegal)

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

Vc8中的for循环中变量的有效期仅仅在for 循环的开始与结束期间有效。
b.string实现

Vc6: string s; char *p = s.begin(); (ok)

Vc8: string s; char *p = s.begin(); (illegal)

string s; char *p = const_cast<char *>(s.c_str()); (ok)

在vc6中,string::iterator被定义为char *,但是vc8中不是
c.更严格的typename声明的需要

Vc6:

template<class T>

class Test

{

public:

typedef map<T,T> mymap;

mymap::iterator mymap_iter;

}; (ok)

Vc8:

template<class T>

class Test

{

public:

typedef map<T,T> mymap;

mymap::iterator mymap_iter;

}; (illegal)

typename mymap::iterator mymap_iter;(ok)

vc8更加严格的要求程序员在类型前面加上typename以避免歧义
d.不允许默认的int类型

Vc6: fun() { return 0;} (ok)

Vc8: fun() { return 0;} (illegal)

int fun() { return 0;} (ok)

vc8不支持默认返回int类型
e.typedef必须是public才能被外界访问到

Vc6:

Class Test

{

typedef int iterator;

};

Test::iterator i; (ok)

Vc8:

Class Test

{

typedef int iterator;

};

Test::iterator i; (illegal)

Class Test

{

public:

typedef int iterator;

};

Test::iterator i; (ok)

附录:一些资源(From msdn)
Overviews:

Moving from 6.0 to 7.1:

Moving from 7.1 to 8.0:

posted on 2012-11-19 23:14  xilentz  阅读(431)  评论(0编辑  收藏  举报