gcc 3.3.1 support placement new w/ initializer?

Started by
3 comments, last by MaulingMonkey 19 years, 8 months ago
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.
Advertisement
Did you include the header new? read this
That's pretty cool, didn't know you could do that.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
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.
Quote:Original post by snk_kid
Did you include the header new? read this


No I didn't. Thanks, that fixed it.

Oddly, placement new works without arguments without the #include < new > statement.

This topic is closed to new replies.

Advertisement