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
What are advantages of using friend classes?
What are the various operations performed on stack?
What is destructor oops?
What is exception handling? Does c++ support exception handling?
Define token in c++.
write a code for this. serial_number contained in the header of the file will be read , if this serial number is less than a previous serial number within a successfully processed file, or is the same as another serial number within a successfully processed file, or if the field contains anything other than 7 digits, then the file must error with the reason ‘Invalid SERIAL_NUMBER’.
What is difference between rand () and srand ()?
what is C++ exceptional handling?
What is a block in c++?
Discuss about iteration statements in C++ .
What is c++ manipulator?
What do the header files usually contains?
What are libraries in c++?
What is buffering in c++?
Tell me what are static member functions?