为什么新建一个字符串也这么多错误?

B2China 2004-09-10 09:02:43
一个WIN32工程(不用MFC)

int nBufSize = 32;
LPSTR pszNewBuf = new char[nBufSize];

编译提示错误:
E:\Pop3.cpp(842) : error C2065: 'DEBUG_NEW' : undeclared identifier
E:\Pop3.cpp(842) : error C2440: 'initializing' : cannot convert from 'int' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\Pop3.cpp(842) : error C2144: syntax error : missing ';' before type 'char'
E:\Pop3\Win32_lin_V2\Pop3.cpp(842) : warning C4091: '' : ignored on left of 'char' when no variable is declared
E:\Pop3.cpp(842) : error C2143: syntax error : missing ';' before '['
E:\Pop3.cpp(842) : error C2143: syntax error : missing ';' before '['

我的DEBUG_NEW在头文件是这么定义的:
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

晕。

...全文
200 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
daylove 2004-09-10
  • 打赏
  • 举报
回复
你是c还是C++??


------------------------------------------------------《爱晶如梦》
『唯我独坐寒江』
『难为春城美景』
『秋黛依影随行』
『紫晶轻舞我心』
同桌老王 2004-09-10
  • 打赏
  • 举报
回复
不用MFC干吗还要用LPSTR?
JuneChin 2004-09-10
  • 打赏
  • 举报
回复
LPSTR pszNewBuf = new LPSTR[nBufSize];
然后在赋值!
grayloach1 2004-09-10
  • 打赏
  • 举报
回复
我听说尽量不要用宏,我是菜鸟,但是问下:

int nBufSize = 32;
LPSTR pszNewBuf = new char[nBufSize]; //LPSTR是不是字符指针类型( char *)啊?
darkstar21cn 2004-09-10
  • 打赏
  • 举报
回复
LPSTR
这个的问题,它的声明在哪?
cpunion 2004-09-10
  • 打赏
  • 举报
回复
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

DEBUG_NEW定义于afx.h,记得要包含这个头文件。

B2China 2004-09-10
  • 打赏
  • 举报
回复
我这个代码是别人做的,我拿来看的。

我在其它一些工程也看到了类似的宏,看不出那个宏定义有什么用
kunp 2004-09-10
  • 打赏
  • 举报
回复
用这个宏来做什么用?
B2China 2004-09-10
  • 打赏
  • 举报
回复
唉,就是那个宏定义的问题了!
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

我如果把这段定义去掉,那么所有的错误一扫而光。不明白
hearlihong 2004-09-10
  • 打赏
  • 举报
回复
太多的格式错误,
和初始化错误
要摸贴出源码,要摸,自己再检查一下。
漂流的代码 2004-09-10
  • 打赏
  • 举报
回复
这样写
LPTSTR pszNewBuf=new TCHAR[nBuffsize];
248406869 2004-09-10
  • 打赏
  • 举报
回复
那个宏是调试版本用的,会比new产生更多的代码供调试用。release版本编译不会使用这个宏。
aXu 2004-09-10
  • 打赏
  • 举报
回复
if you define _DEBUG this macro,you use DEBUG_NEW statement,but in your applacation, you did not include header file assosiate whit it ,so complior give you some error message.you should find some header file include DEBUG_NEW define,and include it.

sorry my english is very pool,but my os is jappese,can't display chinese.

64,651

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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