You forgot to include the
new
header which provides standard library implementations of the placement new (as an alternative, you could provide your own implementations).
The following code compiles and runs fine on my Linux box.
#include <cstdint>
#include <cstdlib>
#include <new>
struct test final {
test() {
printf("test::test()\r\n");
}
~test() {
printf("test::~test()\r\n");
}
};
template <typename T>
T* create(void* buf) {
T* tptr = new (buf) T;
return tptr;
}
int main(int argc, char** argv)
{
uint8_t ptest_buf[sizeof(test)];
test* ptest = create<test>(ptest_buf);
printf("%p\n", ptest);
}