c – 包含STL头文件时出现问题

c – 包含STL头文件时出现问题,第1张

概述我在MFC(VS 2008)中创建了基于Dialog的应用程序.当我在Dlg.cpp中执行“#include”时,它显示以下错误. VS 2008安装中是否缺少某些组件 c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(43) : error C2665: 'operator new' : none of 我在MFC(VS 2008)中创建了基于Dialog的应用程序.当我在Dlg.cpp中执行“#include”时,它显示以下错误.

VS 2008安装中是否缺少某些组件

c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(43) : error C2665: 'operator new' : none of the 5 overloads Could convert all the argument types1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(85): Could be 'voID *operator new(size_t,const std::nothrow_t &) throw()'1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(93): or       'voID *operator new(size_t,voID *)'1>        while trying to match the argument List '(const char [70],int)'1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(145) : see reference to function template instantiation '_Ty *std::_Allocate<char>(size_t,_Ty *)' being compiled1>        with1>        [1>            _Ty=char1>        ]1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(144) : while compiling class template member function 'char *std::allocator<_Ty>::allocate(std::allocator<_Ty>::size_type)'1>        with1>        [1>            _Ty=char1>        ]1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\xstring(2216) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled1>        with1>        [1>            _Ty=char1>        ]1>Build log was saved at "file://c:\Users\Public\documents\Proj\STL1\STL1\DeBUG\BuildLog.htm"1>STL1 - 1 error(s),0 warning(s)========== Build: 0 succeeded,1 Failed,0 up-to-date,0 skipped ==========
解决方法 在您的MFC项目中包含的任何STL都应包含在DEBUG_NEW的定义之前.这在过去是一个问题(似乎不再是,因为我无法在VS 2010中重现它).

// myfile.cpp#ifdef _DEBUG#define new DEBUG_NEW#endif// This will cause the error#include <vector>

// myfile.cpp// will work OK#include <vector>#ifdef _DEBUG#define new DEBUG_NEW#endif

DEBUG_NEW是一个特定于Microsoft的扩展,有助于在应用程序的调试版本中查找内存泄漏.在某些情况下它可能非常有用.

它在afx.h中定义为:

voID* AFX_CDECL operator new(size_t nSize,LPCSTR lpszfilename,int nline);#define DEBUG_NEW new(THIS_file,__liNE__)`

提供对已分配内存的跟踪以及检测到泄漏时,将为您提供分配所在的文件和行号.

总结

以上是内存溢出为你收集整理的c – 包含STL头文件时出现问题全部内容,希望文章能够帮你解决c – 包含STL头文件时出现问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1214045.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存