Menu ▾ ▴

#81 placement new

open
nobody
None
2
2003-01-05
2003-01-05
Yordan
No

Hi,

I'm a c++ programmer and I tried to port some of my
code to palm. Unfortunately my code it makes havy use
of STL. I'm trying build a light version of std::vector but it
requires placement new and I can't get it to compile.

following code:

char pmem[64];
new ((void*)pmem) SomeObject();

gives error message:
\test.cpp: In function `void f()':
<internal>:50: too many arguments to function `void *
operator new(long unsigned int)'
.\test.cpp:50: at this point in file

Kind Regards,
warjo

Discussion

  • John Marshall

    John Marshall - 2003-01-05
    • priority: 5 --> 2
     
  • John Marshall

    John Marshall - 2003-01-05

    Logged In: YES
    user_id=4669

    So define your own placement new operator?

     
  • Yordan

    Yordan - 2003-01-06

    Logged In: YES
    user_id=681185

    > So define your own placement new operator?
    in the <new> header the global placement new definition is
    fine. The problem is that the compiler doesn't actually see the
    experssion "new (ptr) Object();" as a placement new. It thinks
    it is a normal new. No matter how many placement new
    operators I define it will continue to give error... (loook at the
    error in my example)

    -warjo

     
  • Ken Bannister

    Ken Bannister - 2003-06-17

    Logged In: YES
    user_id=803085

    I have just started using placement new, and I cannot
    recreate the original poster's error. The fragment below
    compiles for me.

    char testBuffer[64];
    new((void*) testBuffer) String("test1");

    However, when I omit "#include <new>" from the compilation
    unit, I can recreate the error.

    <internal>:60: too many arguments to function `void *
    operator new(long unsigned int)'
    ../src/VectorBufferTest.cpp:60: at this point in file

    Perhaps the include is the source of the trouble.

     

Log in to post a comment.