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
Explain the static storage classes in c++.
How do you define a class in c++?
What is a class template?
When are exception objects created?
How oops is better than procedural?
What does count ++ do in c++?
Is facebook written in c++?
We all know that a const variable needs to be initialized at the time of declaration. Then how come the program given below runs properly even when we have not initialized p?
How will you execute a stack using a priority queue? (Push and pop should be in O (1)).
What is binary search in c++?
total amount of milk produced each morning and then calculates and outputs the number of cartons needed for this milk , the cost of producing the milk and the profit from producing this milk.
what is the drawback of classical methods in oops?
What is purpose of abstract class?
What is the difference between an enumeration and a set of pre-processor # defines?
What is the renewal class?