问个overloading new operator的问题# Programming - 葵花宝典
p*s
1 楼
在C++里,
我尝试着自己定义一个new operator,
首先我这么来一把搞一个带三个参数的new:
#define mynew new (name, type, align)
然后我overload new 和new[]:
void *operator new(size_t size, const char *ModName, memPool_t *memType, size_t alignment) throw();
new[]的overload类似于上.
然后在code里call
pool = mynew(modName, memType, alignment) myPool;
(myPool为自定义的class)
编译的时候出错,compiler不认我定义的这个operator,说
undefined reference to `operator new(unsigned int,char const*,memPool*,unsigned int).
为啥不认呢? 不会是因为我自定义带三个参数的mynew类型和operator new里四个arg
相冲突吧?
我尝试着自己定义一个new operator,
首先我这么来一把搞一个带三个参数的new:
#define mynew new (name, type, align)
然后我overload new 和new[]:
void *operator new(size_t size, const char *ModName, memPool_t *memType, size_t alignment) throw();
new[]的overload类似于上.
然后在code里call
pool = mynew(modName, memType, alignment) myPool;
(myPool为自定义的class)
编译的时候出错,compiler不认我定义的这个operator,说
undefined reference to `operator new(unsigned int,char const*,memPool*,unsigned int).
为啥不认呢? 不会是因为我自定义带三个参数的mynew类型和operator new里四个arg
相冲突吧?