|
-
June 30th, 2010, 04:17 AM
#1
placement new operator
#include <iostream>
using namespace std;
class addition
{
int a, b;
public:
addition()
{
a=0;
b=0;
}
addition(int x, int y)
{
a = x;
b = y;
}
void show()
{
cout << a << " ";
cout << b << "\n";
}
addition operator+(addition op2);
};
addition addition: perator+(addition op2)
{
addition temp;
temp.a = op2.a + a;
temp.b = op2.b + b;
return temp;
}
int main()
{
char* buf=new char[100];
addition* a1=new (buf) addition(1,3);//placement new operator
return 0;
}
Queries:
i. Is it possible to create object at a memory location on heap? i.e. let's say memory locaiton 2134433 present on heap....If yes, pl provide the code?
ii. In the above code, what is the use of placement new opearator as we dont know address of memory location where object is getting creating?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|