- /*
- * 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 _CharT, class _Traits, class _Alloc> class std::__cxx11::basic_string? used without template arguments
- * 12 | void *basic_string::operator new(size_t size)
- * | ^~~~~~~~~~~~
- */
- #include <iostream>
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- 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;
- }
Custom basic_string::operator new()
Posted by Anonymous on Mon 13th Jun 2022 15:57
raw | new post
view followups (newest first): Error message for Custom basic_string::operator new() by Anonymous
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.