ACE封装的malloc前面加了两个冒号为什么编译不过

zjtzlqr 2014-09-08 10:08:07
#if !defined (ACE_MALLOC_FUNC)
# define ACE_MALLOC_FUNC ::malloc


namespace ACE_OS
{
extern ACE_Export
void *malloc (size_t);
} /* namespace ACE_OS */


void *
ACE_OS::malloc (size_t nbytes)
{
return ACE_MALLOC_FUNC (nbytes);
}

ACE源码是这样的。。
我模仿了如下的代码


//#include <iostream>
#include <sys/socket.h>
#include <sys/epoll.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

#define TEST_MALLOC_FUNC ::malloc


namespace TEST_OS
{
void *malloc (size_t);
}




void *TEST_OS::malloc (size_t nbytes)
{
return TEST_MALLOC_FUNC (nbytes);
}




int main()
{
TEST::malloc(10);


编译的时候报错
In function ‘void* TEST_OS::malloc(size_t)’:
error: ‘::malloc’ has not been declared
...全文
149 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjtzlqr 2014-09-08
  • 打赏
  • 举报
回复
谢谢,一语惊醒梦中人啊。。。
勤奋的小游侠 2014-09-08
  • 打赏
  • 举报
回复
#define TEST_MALLOC_FUNC ::malloc 这一句,::malloc ,你别以为这个函数编译器会帮你变出来,是要头文件的。 可以用malloc.h或 alloc.h (注意:alloc.h 与 malloc.h 的内容是完全一致的),而在Visual C++6.0中可以用malloc.h或者stdlib.h。 不同的系统要include到相应的头文件才行。 ACE是自己封装了对应的头文件

64,648

社区成员

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

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