|
||
|
Overloading the operators new and delete Placement syntax of the new operator The placement syntax provides a comma-separated argument list used to select an overloaded operator new() with a matching signature. These additional arguments are often used to place the constructed object at a particular address. This form of operator new uses the new.h header file. For example:
//Placement syntax and new overloaded.
#include <iostream.h>
#include <new.h>
char* buf1 = new char[1000]; //in place of free store
char* buf2 = new char[1000];
class object {
public:
.....
private:
.....
};
void main()
{
object *p = new(buf1) object; //allocate at buf1
object *q = new(buf2) object; //allocate at buf2
.....
}
|
||
|
|
||