• Advertisement
Sign in to follow this  

gcc 3.3.1 support placement new w/ initializer?

This topic is 4948 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Although I have seen examples of using placement new with an argument to the constructor as so:
class ClassType {
public:
  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
Advertisement
Quote:
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
Sign in to follow this  

  • Advertisement