再谈从vc6迁移到vs2005

来源:互联网 发布:vb编辑器是用来 编辑:程序博客网 时间:2024/04/29 02:13
作为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:
  • 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
 
原创粉丝点击