pastebin - collaborative debugging tool
rovema.kpaste.net RSS

Difference between
modified post 05a47e7c by Anonymous on Mon 13th Jun 2022 15:58
original post 85c7c607e by Anonymous on Mon 13th Jun 2022 15:57
Download diff
Show old version | new version | both versions

    
1+
$ clang++ -std=gnu++11 -g std_string_custom_new1.cpp
19
2-
/*
10+
3-
 * Custom basic_string::operator new() - does not work yet
11+
4-
 *
12+
5-
 * $ g++ -std=gnu++11 -g std_string_custom_new1.cpp
13+
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
14+
7-
 *  12 | void *basic_string::operator new(size_t size)
15+
8-
 *     |       ^~~~~~~~~~~~
16+
9-
 */
17+
1018
11-
#include <iostream>
19+
12-
#include <stdlib.h>
20+
13-
#include <stdio.h>
21+
14-
#include <unistd.h>
22+
1523
16-
using namespace std;
24+
1725
18-
char mymemoryarena[65536];
26+
19-
size_t mymemoryarena_index = 0;
27+
2028
21-
void *basic_string::operator new(size_t size)
29+
22-
{
30+
23-
	write(1, "#mark", 5);
31+
24-
	void *ptr = &mymemoryarena[mymemoryarena_index];
32+
2533
26-
	mymemoryarena_index += size;
34+
2735
28-
	return ptr;
36+
29-
}
37+
3038
31-
int main(int ac, char *av[])
39+
32-
{
40+
33-
	(void)puts("#start.");
41+
3442
35-
	string *x1 = new string("hello");
43+
36-
	string *x2 = new string("world");
44+
3745
38-
	string x3 = *x1 + string(" ") + *x2;
46+
3947
40-
	cout << x3 << endl;
48+
4149
4250
43-
	(void)puts("#done.");
51+
44-
	return EXIT_SUCCESS;
52+
45-
}
53+
4654

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