R
Roy Smith
After 6 or 7 years of doing C++, I've never had a need to use
placement new, but I'm playing with it now just to make sure I
understand the concept. I thought I did, but my compiler (g++ i686-
apple-darwin9-g++-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465))
disagrees When I compile this:
#include <stdlib.h>
class MyClass {
int i;
};
int main(int, const char**) {
void* block = malloc(sizeof(MyClass));
MyClass* m = new(block) MyClass;
return 0;
}
I get:
new.cpp: In function ‘int main(int, const char**)’:
new.cpp:9: error: no matching function for call to ‘operator new(long
unsigned int, void*&)’
<built-in>:0: note: candidates are: void* operator new(long unsigned
int)
Changing it to "::new" gives essentially the same error. What am I
not groking here?
placement new, but I'm playing with it now just to make sure I
understand the concept. I thought I did, but my compiler (g++ i686-
apple-darwin9-g++-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465))
disagrees When I compile this:
#include <stdlib.h>
class MyClass {
int i;
};
int main(int, const char**) {
void* block = malloc(sizeof(MyClass));
MyClass* m = new(block) MyClass;
return 0;
}
I get:
new.cpp: In function ‘int main(int, const char**)’:
new.cpp:9: error: no matching function for call to ‘operator new(long
unsigned int, void*&)’
<built-in>:0: note: candidates are: void* operator new(long unsigned
int)
Changing it to "::new" gives essentially the same error. What am I
not groking here?