Answer Posted / ritesh pal
When you want to call a constructor directly, you use the placement new. Sometimes you have some raw memory that's already been allocated, and you need to construct an object in the memory you have. Operator new's special version placement new allows you to do it.
class Widget
{
public :
Widget(int widgetsize);
...
Widget* Construct_widget_int_buffer(void *buffer,int widgetsize)
{
return new(buffer) Widget(widgetsize);
}
};
This function returns a pointer to a Widget object that's constructed within the buffer passed to the function. Such a function might be useful for applications using shared memory or memory-mapped I/O, because objects in such applications must be placed at specific addresses or in memory allocated by special routines.
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How compile and run c++ program in turbo c++?
Why c++ is not a pure oop language?
Write a program to generate the Fibonocci Series in C++.
What is the full form of oops?
What are the benefits of interface?
the maximum length of a character constant can be a) 2 b) 1 c) 8
Should I learn c or c++ first?
What are the five basic elements of a c++ program?
Whats oop mean?
Is c++ the hardest language?
Define namespace in c++?
What is the use of c++ programming language in real life?
Is c++ map a hash table?
What is class in oop with example?
Write a program to find the Fibonacci series recursively.