求教高手no instance of overloaded 【new】错误如何解决
时间:2010-08-13
来源:互联网
--demo.h
#ifndef _DEMO_H
#define _DEMO_H
#endif
class TestObj
{
public:
char z[15];
TestObj():z(""
{}
void* operator new( size_t nSize )
{
return :
perator new( nSize );
}
virtual ~TestObj() {};
};
---demo.cpp
#include <stdio.h>
#include "demo.h"
using namespace std;
#if defined( MEM_DEBUG )
#include "MemRecord.h"
#define new new( __FILE__, __LINE__ )
#endif
/******************MemRecord.cpp里对NEW进行了重载,如下****************************
void* operator new( size_t nSize, char* pszFileName, int nLineNum )
{
MemOperation record;
void *pResult;
pResult = :
perator new( nSize );
if ( pResult )
{
// record the alloc memory
strncpy( record.Filename, pszFileName, FILENAME_LENGTH - 1 );
record.Filename[ FILENAME_LENGTH - 1 ] = '\0';
record.LineNum = nLineNum;
record.AllocSize = nSize;
record.OperationType = SINGLE_NEW;
record.errCode = 0;
record.pBuffer = pResult;
appMemory.Insert( pResult, &record );
appMemory.InsertDB( &record );
}
return pResult;
}
******************************************************************************/
int main()
{
TestObj* pob = new TestObj;
return 0;
}
-------
编译出错
"demo.cpp", line 39: error #2384: no instance of overloaded
"TestObj:
perator new" matches the argument list
argument types are: (unsigned long, const char [9], int)
TestObj* pob = new TestObj;
^
1 error detected in the compilation of "demo.cpp".
#ifndef _DEMO_H
#define _DEMO_H
#endif
class TestObj
{
public:
char z[15];
TestObj():z(""

void* operator new( size_t nSize )
{
return :

}
virtual ~TestObj() {};
};
---demo.cpp
#include <stdio.h>
#include "demo.h"
using namespace std;
#if defined( MEM_DEBUG )
#include "MemRecord.h"
#define new new( __FILE__, __LINE__ )
#endif
/******************MemRecord.cpp里对NEW进行了重载,如下****************************
void* operator new( size_t nSize, char* pszFileName, int nLineNum )
{
MemOperation record;
void *pResult;
pResult = :

if ( pResult )
{
// record the alloc memory
strncpy( record.Filename, pszFileName, FILENAME_LENGTH - 1 );
record.Filename[ FILENAME_LENGTH - 1 ] = '\0';
record.LineNum = nLineNum;
record.AllocSize = nSize;
record.OperationType = SINGLE_NEW;
record.errCode = 0;
record.pBuffer = pResult;
appMemory.Insert( pResult, &record );
appMemory.InsertDB( &record );
}
return pResult;
}
******************************************************************************/
int main()
{
TestObj* pob = new TestObj;
return 0;
}
-------
编译出错
"demo.cpp", line 39: error #2384: no instance of overloaded
"TestObj:

argument types are: (unsigned long, const char [9], int)
TestObj* pob = new TestObj;
^
1 error detected in the compilation of "demo.cpp".
作者: sotjimmy 发布时间: 2010-08-13
为了检测内存泄露,重载了NEW,记录下他的文件名的行数;
但是放到工程用发现工程也有对NEW的重载,比如demo.h这个列子,由于工程文件不能改变
所以要怎么才能把让重载的NEW和工程里重载的new不冲突呢
但是放到工程用发现工程也有对NEW的重载,比如demo.h这个列子,由于工程文件不能改变
所以要怎么才能把让重载的NEW和工程里重载的new不冲突呢
作者: sotjimmy 发布时间: 2010-08-13
---demo.cpp
#include <stdio.h>
#include "demo.h"
using namespace std;
#if defined( MEM_DEBUG )
#include "MemRecord.h"
#define new new( __FILE__, __LINE__ )
#endif
int main()
{
TestObj* pob = new TestObj;
return 0;
}
#include <stdio.h>
#include "demo.h"
using namespace std;
#if defined( MEM_DEBUG )
#include "MemRecord.h"
#define new new( __FILE__, __LINE__ )
#endif
int main()
{
TestObj* pob = new TestObj;
return 0;
}
作者: sotjimmy 发布时间: 2010-08-13
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28