[转]VC6 和 VC2008(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:

What's new in 8.0
What's new in 7.1
What's new in 7.0
Moving from 6.0 to 7.1:

ATL/MFC Breaking changes (6.0 to 7.0) (also seen here but the list isn't as long)
ATL/MFC Breaking changes (7.0 to 7.1)
Standard c++ Library changes and issues specific to upgrading
Compiler breaking changes
In-depth info on increased standards compliance
Project upgrading
Moving from 7.1 to 8.0:

Libraries breaking changes
ATL obsolete topics and deprecated functions with replacements
MFC obsolete topics
Compiler breaking changes
Deprecated compiler options
Some removed linker options (mentioned here and here)
Preprocessor changes
文章出处:http://www.diybl.com/course/3_program/vc/vc_js/2008914/142770.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值