#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:

C++ operator new 重载(两个参数)


PS:

    还可以有多个参数:void* operator new (size_t classSize, int paraA, int paraB, int paraC);

    写法: ClassA *pClassA = new (paraA, paraB, paraC)ClassA;

相关文章:

  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-15
  • 2022-12-23
  • 2021-06-02
  • 2022-02-15
  • 2021-05-21
  • 2021-05-27
  • 2021-08-18
相关资源
相似解决方案