我有这样的代码段
#include <cstring>
#define DISABLE_DEFAULT_NEW \
void* operator new(size_t aSize, void* aPtr); \
void operator delete(void* aPtr);
class A
{
public:
DISABLE_DEFAULT_NEW
A() {}
};
int
main()
{
A* a = new A();
return 0;
}
编译时,会看到类似这样的错误消息
disable_new.cpp:17:10: error: no matching function for call to 'operator new'
A* a = new A();
^
disable_new.cpp:9:3: note: candidate function not viable: requires 2 arguments, but 1 was provided
DISABLE_DEFAULT_NEW
^
disable_new.cpp:3:9: note: expanded from macro 'DISABLE_DEFAULT_NEW'
void* operator new(size_t aSize, void* aPtr); \
^
1 error generated.
我的问题是默认的新运算符在哪里?我希望new的默认语法仍然有效,规范中是否提到了行为问题?
他们只是隐藏