C2248编译错误的原因和解决--VC6向VC7.1迁移真是累死人,N多编译错误
把以前VC6先寫(xiě)好的類加入VC7中,編譯時(shí)竟然錯(cuò)誤多到編譯器無(wú)法接受而停止,hooooo.真的好煩,要是有個(gè)工具修改外加的.h和cpp文件就好了...
遇到最多的是C2248編譯錯(cuò)誤,才發(fā)現(xiàn)VC7提升了對(duì)基類成員訪問(wèn)的檢測(cè)。
下面記錄一些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里是無(wú)法訪問(wèn) private typedef!(C2248)但6.0卻是可以,累了。。。
Improved accessibility checks in compiler now detect inaccessible base classes (C2248).
C2248的產(chǎn)生原因之一:從“類”創(chuàng)建的對(duì)象無(wú)法訪問(wèn)該“類”的 protected 或 private 成員。
為使代碼在 Visual C++ 的 Visual Studio?.NET 2003 和 Visual Studio?.NET 版本中都有效,使用范圍運(yùn)算符。
如果調(diào)試器表達(dá)式引用不明確的成員名稱,必須使用類名稱來(lái)限定它。
例如,如果 CObject 是 CClass 實(shí)例,后者從 AClass 和 BClass
二者中繼承了名為 expense 的成員函數(shù),則 CObject.expense 是不明確的。
可以按如下方式化解多義性:
轉(zhuǎn)載于:https://www.cnblogs.com/babyblue/archive/2005/05/28/164210.html
總結(jié)
以上是生活随笔為你收集整理的C2248编译错误的原因和解决--VC6向VC7.1迁移真是累死人,N多编译错误的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 如何判断一个字符串的编码类型?
- 下一篇: 常用基类名称空间