pastebin - collaborative debugging tool
rovema.kpaste.net RSS


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

  1.  
  2. /*
  3.  * Custom basic_string::operator new() - does not work yet
  4.  *
  5.  * $ g++ -std=gnu++11 -g std_string_custom_new1.cpp
  6.  * std_string_custom_new1.cpp:12:7: error: ?template<class _CharT, class _Traits, class _Alloc> class std::__cxx11::basic_string? used without template arguments
  7.  *  12 | void *basic_string::operator new(size_t size)
  8.  *     |       ^~~~~~~~~~~~
  9.  */
  10.  
  11. #include <iostream>
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include <unistd.h>
  15.  
  16. using namespace std;
  17.  
  18. char mymemoryarena[65536];
  19. size_t mymemoryarena_index = 0;
  20.  
  21. void *basic_string::operator new(size_t size)
  22. {
  23.         write(1, "#mark", 5);
  24.         void *ptr = &mymemoryarena[mymemoryarena_index];
  25.        
  26.         mymemoryarena_index += size;
  27.  
  28.         return ptr;
  29. }
  30.  
  31. int main(int ac, char *av[])
  32. {
  33.         (void)puts("#start.");
  34.        
  35.         string *x1 = new string("hello");
  36.         string *x2 = new string("world");
  37.        
  38.         string x3 = *x1 + string(" ") + *x2;
  39.        
  40.         cout << x3 << endl;
  41.  
  42.  
  43.         (void)puts("#done.");
  44.         return EXIT_SUCCESS;
  45. }

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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at