包括STL头文件中的问题 [英] Problem in including STL header files

查看:166
本文介绍了包括STL头文件中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MFC(VS 2008)中创建了基于Dialog的应用程序。当我在Dlg.cpp中执行#include时,显示以下错误。

I have created Dialog Based application in MFC (VS 2008).When I do "#include" in Dlg.cpp it showing following error.

在VS 2008安装中缺少

Is Some Component is missing in the VS 2008 Installation

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 types

1>        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 compiled

1>        with

1>        [
1>            _Ty=char
1>        ]

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>        with
1>        [
1>            _Ty=char
1>        ]

1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\xstring(2216) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled

1>        with
1>        [
1>            _Ty=char
1>        ]

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 ==========


推荐答案

STL包括在您的MFC项目中应该包括在DEBUG_NEW的定义之前。这是一个过去的问题(不再似乎是,因为我不能在VS 2010中重现它)。

Any STL includes in your MFC project should be included prior to the definition of DEBUG_NEW. This was a problem in the past (no longer seems to be, as I cannot reproduce it in 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


$ b b

DEBUG_NEW 是一个微软专用扩展,有助于在应用程序的调试版本中查找内存泄漏。

DEBUG_NEW is a microsoft specific extension that helps to find memory leaks in debug versions of the application. It can be very useful in certain cases.

在afx.h中定义为:

It's defined in afx.h as:

void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
#define DEBUG_NEW new(THIS_FILE, __LINE__)`

这有助于追踪记忆分配,并且当检测到泄漏时将给您分配发生的文件和行号。

It's helps to provide tracking of memory allocated and when a leak is detected will give you the file and line number where the allocation took place.

这篇关于包括STL头文件中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆