Lets say I have a class A and I overload operator new in the class.
class A{
public:
A();
void *operator new(size_t size);
void operator delete(void *p);
}
How would I use this overloaded operator new inside of class A instead of the global new?
For example
A::A(){
...
int *temp = new int[10]; //Use overloaded new and not global new
}
I looked around and I don’t think I saw a question that addressed this.
Thanks!
That overloaded version will be used for creating objects of
class Aand its descendants only – such as when you havenew A()in your code. It won’t be called fornew A[]unless you overloadoperator new[]()as well.In order to have your
operator new[]()function used when you donew int[]you have to replace globaloperator new()[]function.