P
pauldepstein
If Fred is a class, I am often confused by the appearance of Fred()
instead of Fred
Here is an example from a well-established c++ website:
#include <new> // Must #include this to use "placement new"
#include "Fred.h" // Declaration of class Fred
void someCode()
{
char memory[sizeof(Fred)]; // Line #1
void* place = memory; // Line #2
Fred* f = new(place) Fred(); // Line #3 (see "DANGER" below)
// The pointers f and place will be equal
...
}
I do believe that I understand this code. However, I would write
Fred* f = new(place) Fred;
After all, for the more usual new, the format is pointer = new type;
It is _not_ pointer = new type();
The class Fred is called Fred not Fred(). What are these final
brackets doing?
Paul
instead of Fred
Here is an example from a well-established c++ website:
#include <new> // Must #include this to use "placement new"
#include "Fred.h" // Declaration of class Fred
void someCode()
{
char memory[sizeof(Fred)]; // Line #1
void* place = memory; // Line #2
Fred* f = new(place) Fred(); // Line #3 (see "DANGER" below)
// The pointers f and place will be equal
...
}
I do believe that I understand this code. However, I would write
Fred* f = new(place) Fred;
After all, for the more usual new, the format is pointer = new type;
It is _not_ pointer = new type();
The class Fred is called Fred not Fred(). What are these final
brackets doing?
Paul