vc6.0转换Vs2008 错误error C2365: 'operator new'

jcdd188 2011-04-28 05:53:27
网上说是new operator重载问题
代码里只有一处有
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
我把他注释掉了 一样有这个错误

1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(32) : warning C4229: anachronism used : modifiers on data are ignored
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(32) : error C2365: 'operator new' : redefinition; previous definition was 'function'
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(32) : error C2078: too many initializers
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(32) : error C2440: 'initializing' : cannot convert from 'int' to 'void *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(32) : error C2143: syntax error : missing ';' before '('
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(32) : error C2226: syntax error : unexpected type 'size_t'
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(33) : error C2059: syntax error : ')'
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(36) : warning C4229: anachronism used : modifiers on data are ignored
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(36) : error C2365: 'operator new' : redefinition; previous definition was 'function'
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(36) : error C2078: too many initializers
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(36) : error C2440: 'initializing' : cannot convert from 'int' to 'void *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(36) : error C2143: syntax error : missing ';' before '['
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(36) : error C3409: empty attribute block is not allowed
1>d:\program files\microsoft visual studio 9.0\vc\include\xdebug(36) : error C2226: syntax error : unexpected type 'size_t'
1>d:\program files\microsoft visual studio 9.0\vc\include\xlocale(143) : error C2059: syntax error : 'string'
1>d:\program files\microsoft visual studio 9.0\vc\include\xlocale(144) : error C2091: function returns function
1>d:\program files\microsoft visual studio 9.0\vc\include\xlocale(144) : error C2802: static member 'operator new' has no formal parameters
1>d:\program files\microsoft visual studio 9.0\vc\include\xlocale(144) : error C2333: 'std::locale::facet::operator new' : error in function declaration; skipping function body
1>d:\program files\microsoft visual studio 9.0\vc\include\xlocale(149) : error C2059: syntax error : 'string'
1>d:\program files\microsoft visual studio 9.0\vc\include\xlocale(151) : error C2091: function returns function
1>d:\program files\microsoft visual studio 9.0\vc\include\xlocale(151) : error C2556: 'void *(__cdecl *std::locale::facet::operator new(void))(size_t,const std::_DebugHeapTag_t &,char *,int)' : overloaded function differs only by return type from 'void *(__cdecl *std::locale::facet::operator new(void))(size_t)'
...全文
715 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
godion 2012-04-05
  • 打赏
  • 举报
回复
I found the cause of the problem, I added the header file after the
following declarations

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

The header file must be added before those.

Ref: http://marc.info/?l=log4cxx-user&m=108972054520600
昵称测试 2011-08-06
  • 打赏
  • 举报
回复
我也遇到同样的 问题 已然存在
jcdd188 2011-04-29
  • 打赏
  • 举报
回复
问题解决了 是其他地方重载了operator new 与xdebug里的发生了冲突 我直接删掉就好了 谢谢楼上两位
xiaopoy 2011-04-28
  • 打赏
  • 举报
回复
这个肯定是因为你include头文件的顺序有问题。不妨检查下出错的源代码里,头文件里分析include了哪些,头文件里include的也统计出来。这样一个个去除include的目标来排查重复include的问题。
hhh_hao 2011-04-28
  • 打赏
  • 举报
回复
#define new DEBUG_NEW, //不要干这种事情....
代码静态分析工具PC-LINT安装配置 PC-Lint是C/C++软件代码静态分析工具,你可以把它看作是一种更加严格的编译器。它不仅可以检查出一般的语法错误,还可以检查出那些虽然符合语法要求但不易发现的潜在错误。 C语言的灵活性带来了代码效率的提升,但相应带来了代码编写的随意性,另外C编译器不进行强制类型检查,也带来了代码编写的隐患。PCLint识别并报告C语言中的编程陷阱和格式缺陷的发生。它进行程序的全局分析,能识别没有被适当检验的数组下标,报告未被初始化的变量,警告使用空指针,冗余的代码,等等。软件除错是软件项目开发成本和延误的主要因素。PClint能够帮你在程序动态测试之前发现编码错误。这样消除错误的成本更低。 使用PC-Lint在代码走读和单元测试之前进行检查,可以提前发现程序隐藏错误,提高代码质量,节省测试时间。并提供编码规则检查,规范软件人员的编码行为。 由于PC-LINT对于一般程序员来说可能比较陌生,有好多人安装了也不知道怎样配置和使用。 下面我就根据自己的安装和配置心得对PC-Lint的安装、配置及使用进行下详细说明.本人主要介绍了将PC-Lint集成到VC++6.0和SourceInsight的方法和步骤。 (一)Windows下C/C++开发工具中,VC6使用较为普遍,因此这里先讲下VC6.0环境中集成pclint的步骤. 首先, 当然要下载软件,正版软件要200多$呢,买不起!所以只好网上找免费的拉。从http://www.61ic.com/down/othe/pclint.rar处可以下载到一个8.0版本的pclint. 1.将pclint.rar解压至c:\, 这样lint文件就位与c:\pclint(安装目录)下了。 2.将c:\pclint\lnt 下的3个文件lib-w32.lnt,env-vc6.lnt,co-msc60.lnt拷贝至c:\pclint下, 再在安装目录下创建std.lnt和options.lnt两个文件,其中std.lnt的内容如下 // contents of std.lnt c:\pclint\co-msc60.lnt c:\pclint\lib-w32.lnt c:\pclint\options.lnt -si4 -sp4 -i"D:\Program Files;D:\Program Files\Microsoft Visual Studio\VC98\Include" //end 其中-i后面的路径名为VC的安装路径和VC Include 文件路径,根据自己的修改便可。 options.lnt 内容可为空,为定制内容,以后需要时再添加。 准备工作做完了,下一步就是要将pclint集成到VC6中去,先配置lint使之能对单个C或C++文件进行检查。 1.打开VC6,tools--->customize-->tools 新建一个名为pclint的项,在下面填入 command: C:\pclint\lint-nt.exe arguments: -u c:\pclint\std.lnt c:\pclint\env-vc6.lnt "$(FilePath)" Use Output Window 打上勾 close 完成。 这个在你VC窗口tools菜单下应该多了一个pclint选项,可以用它来运行lint程序,对你的c/c++代码进行静态检查了。 现在就可以用个小程序测试一下pclint了 //test1.cpp #include class X { int *p; public: X() { p = new int[20]; } void init() { memset( p, 20, 'a' ); } ~X() { delete p; } }; 编译这个文件,看下你的编译器给你多少警告,再运行下lint, 可以自己对比一下。 我的机器上,VC产生0 errors 0 warnings, 而lint程序产生了如下8条警告信息,有些还是很有用处的提示,这里就不一一分析了. test.cpp(12): error 783: (Info -- Line does not end with new-line) test.cpp(7): error 1732: (Info -- new in constructor for class 'X' which has no assignment operator) test.cpp(7): error 1733: (Info -- new in constructor for class 'X' which has no copy constru
c语言编译程序 Version 4.9.9.1 * Many bug fixes * Improved editor Version 4.9.9.0 * Support for latest Mingw compiler system builds * Bug fixes Version 4.9.8.9 * New code tooltip display * Improved Indent/Unindent and Remove Comment * Improved automatic indent * Added support for the "interface" keyword * WebUpdate should now report installation problems from PackMan * New splash screen and association icons * Improved installer * Many bug fixes Version 4.9.8.7 * Added support for GCC > 3.2 * Debug variables are now resent during next debug session * Watched Variables not in correct context are now kept and updated when it is needed * Added new compiler/linker options: - Strip executable - Generate instructions for a specific machine (i386, i486, i586, i686, pentium, pentium-mmx, pentiumpro, pentium2, pentium3, pentium4, k6, k6-2, k6-3, athlon, athlon-tbird, athlon-4, athlon-xp, athlon-mp, winchip-c6, winchip2, k8, c3 and c3-2) - Enable use of processor specific built-in functions (mmmx, sse, sse2, pni, 3dnow) * "Default" button in Compiler Options is back * Error messages parsing improved * Bug fixes Version 4.9.8.5 * Added the possibility to modify the value of a variable during debugging (right click on a watch variable and select "Modify value") * During Dev-C++ First Time COnfiguration window, users can now choose between using or not class browser and code completion features. * Many bug fixes Version 4.9.8.4 * Added the possibility to specify an include directory for the code completion cache to be created at Dev-C++ first startup * Improved code completion cache * WebUpdate will now backup downloaded DevPaks in Dev-C++\Packages directory, and Dev-C++ executable in devcpp.exe.BACKUP * Big speed up in function parameters listing while editing * Bug fixes Version 4.9.8.3 * On Dev-C++ first time configuration dialog, a code completion cache of all the standard include files can now be generated. * Improved WebUpdate module * Many bug fixes Version

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧