当前位置:首页 > 服务端 > C2248编译错误的原因和解决--VC6向VC7.1迁移真是累死人,N多编译错误

C2248编译错误的原因和解决--VC6向VC7.1迁移真是累死人,N多编译错误

把以前VC6先写好的类加入VC7中,编译时竟然错误多到编译器无法接受而停止,hooooo.真的好烦,要是有个工具修改外加的.h和cpp文件就好了...

遇到最多的是C2248编译错误,才发现VC7提升了对基类成员访问的检测。

下面记录一些MSDN里提到的

VC++编译器重大修改

This topic summarizes the compile-time errors and warnings that will now be issued on code that compiled without errors or warnings in Visual Studio .NET or earlier versions.

  • Closing parentheses now required for the defined preprocessor directive (C2004).
  • Explicit specializations no longer find template parameters from primary template (C2146).
  • A protected member (n) can only be accessed through a member function of a class (B) that inherits from the class (A) of which it (n) is a member (C2247).
  • Improved accessibility checks in compiler now detect inaccessible base classes (C2248).
  • An exception cannot be caught if the destructor and/or copy constructor is inaccessible (C2316).
  • Default arguments on pointers to functions no longer allowed (C2383).
  • A static data member cannot be initialized via derived class (C2477).
  • The initialization of a typedef is not allowed by the standard and now generates a compiler error (C2513).
  • bool is now a proper type (C2632).
  • A UDC can now create ambiguity with overloaded operators (C2666).
  • More expressions are now considered valid null pointer constants (C2668).
  • template<> is now required in places where the compiler would previously imply it (C2768).
  • The expilicit specialization of a member function ourside the class is not valid if the function has already been explicitly specialized via a template class specialization. (C2910).
  • Floating point non-type template parameters are no longer allowed (C2993).
  • Class templates are not allowed as template type arguments (C3206).
  • Friend function names are no longer introduced into containing namespace (C3767).
  • The compiler will no longer accept extra commas in a macro (C4002).
  • An object of POD type constructed with an initializer of the form () will be default-initialized (C4345).
  • typename is now required if a dependent name is to be treated as a type (C4346).
  • Functions that were incorrectly considered template specializations are no longer considered so (C4347).
  • Static data members cannot be initialized via derived class (C4356).
  • A class template specialization needs to be defined before it was used in a return type (C4686).
  • The compiler now reports unreachable code (C4702).

 

 最烦人的在VC7里是无法访问 private typedef!(C2248)但6.0却是可以,累了。。。
Improved accessibility checks in compiler now detect inaccessible base classes (C2248).

C2248的产生原因之一:从“类”创建的对象无法访问该“类”的 protected private 成员。

为使代码在 Visual C++ 的 Visual Studio .NET 2003 和 Visual Studio .NET 版本中都有效,使用范围运算符

// C2248c.cpp
// compile with: /LD
struct A
{
};

struct B: private A
{
};

struct C: B
{
   void f()
   {
      A *p1 = (A*) this;   // C2248
      ::A *p2 = (::A*) this;   // OK
   }
};







如果调试器表达式引用不明确的成员名称,必须使用类名称来限定它。
例如,如果 CObjectCClass 实例,后者从 AClassBClass
二者中继承了名为 expense 的成员函数,则 CObject.expense 是不明确的。
可以按如下方式化解多义性:

CObject.BClass::expense

作者:CZoneSoft
来源链接:https://www.cnblogs.com/babyblue/archive/2005/05/28/164210.html

版权声明:
1、Java侠(https://www.javaxia.com)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaxia.com/server/125625.html

分享给朋友:

“C2248编译错误的原因和解决--VC6向VC7.1迁移真是累死人,N多编译错误” 的相关文章