A
asit
new does the following two things.
1>allocate memory
2>calls constructor
can I avoid the 2nd step ?
1>allocate memory
2>calls constructor
can I avoid the 2nd step ?
new does the following two things.
1>allocate memory
2>calls constructor
can I avoid the 2nd step ?
new does the following two things.
1>allocate memory
2>calls constructor
can I avoid the 2nd step ?
new does the following two things.
1>allocate memory
2>calls constructor
can I avoid the 2nd step ?
Goran said:By the way, if not calling a constructor is important to you, and if
you want to have an object on the stack, you can do this:
#define MAKE_OBJ_REF(name, type) void* ____ = alloca(sizeof type);
What you could do instead is to use a bit of trickery:
unsigned char buffer[sizeof(type)];
type* obj = reinterpret_cast<type*>(buffer);
Unless 'type' is a POD type, be prepared for undefined behavior if
you don't construct the object with placement new (and destroy it by
calling its destructor explicitly).
What you could do instead is to use a bit of trickery:
unsigned char buffer[sizeof(type)];
type* obj = reinterpret_cast<type*>(buffer);
Unless 'type' is a POD type, be prepared for undefined behavior if
you don't construct the object with placement new (and destroy it by
calling its destructor explicitly).
asit said:new does the following two things.
1>allocate memory
2>calls constructor
can I avoid the 2nd step ?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.