Sign in to follow this  

gcc 3.3.1 support placement new w/ initializer?

Recommended Posts

Although I have seen examples of using placement new with an argument to the constructor as so:
class ClassType {
  ClassType( int ) { }

int main ( int argc, char ** argv )
  char memory[sizeof(ClassType)];
  new ((void *)memory) ClassType( 3 ); //<--- the problem
GCC 3.3.1 refuses to compile it, giving the message:
<internal>:9: error: too many arguments to function `void* operator new(unsigned int)'
Does GCC 3.3.1 just not support placement new with initializers? I've tried to google this, but failed miserably. Or if anyone with a modern M$ compiler can try simply compiling that statement, and tell me if it does in fact actually compile or not.

Share this post

Link to post
Share on other sites
Original post by smart_idiot
That's pretty cool, didn't know you could do that.

Thats only the begining with placement new you could create instances statically or using shared memory model, pool-allocation, for garabge collected heap etc, etc.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this