-, , sizeof(T) , . , , void , . .
, , , . , . :
#include <new> // for placement new
#include <stdlib.h> // in this example code, the memory will be allocated with malloc
#include <string> // we will allocate a std::string there
#include <iostream> // we will output it
int main()
{
void* memory_for_string = malloc(sizeof(string));
if (memory_for_string == 0)
return EXIT_FAILURE;
std::string* mystring = new(memory_for_string) std::string("Hello");
*mystring += " world";
std::cout << *mystring << std::endl;
mystring->~string();
free(memory_for_string);
return EXIT_SUCCESS;
}