#include <iostream>
class A
{
public:
int i;
public:
void* operator new (size_t a, size_t b)
{
std::cout << "a: " << a << ",b: " << b << std::endl;
return NULL;
}
};
int main()
{
A *pInt = NULL;
pInt = new (10)A;
return 0;
}
Result of ouput:
PS:
还可以有多个参数:void* operator new (size_t classSize, int paraA, int paraB, int paraC);
写法: ClassA *pClassA = new (paraA, paraB, paraC)ClassA;