/* * Custom basic_string::operator new() - does not work yet * * $ g++ -std=gnu++11 -g std_string_custom_new1.cpp * std_string_custom_new1.cpp:12:7: error: ?template class std::__cxx11::basic_string? used without template arguments * 12 | void *basic_string::operator new(size_t size) * | ^~~~~~~~~~~~ */ #include #include #include #include using namespace std; char mymemoryarena[65536]; size_t mymemoryarena_index = 0; void *basic_string::operator new(size_t size) { write(1, "#mark", 5); void *ptr = &mymemoryarena[mymemoryarena_index]; mymemoryarena_index += size; return ptr; } int main(int ac, char *av[]) { (void)puts("#start."); string *x1 = new string("hello"); string *x2 = new string("world"); string x3 = *x1 + string(" ") + *x2; cout << x3 << endl; (void)puts("#done."); return EXIT_SUCCESS; }