File: s-dwarf3.cpp

package info (click to toggle)
uftrace 0.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,356 kB
  • sloc: ansic: 49,770; python: 11,181; asm: 837; makefile: 769; sh: 637; cpp: 627; javascript: 191
file content (53 lines) | stat: -rw-r--r-- 851 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <algorithm>
#include <iostream>

template <typename T>
class C {
    public:
	C(T v, const char *s)
	{
		construct(v, s);
	}

	C(const C<T> &t)
	{
		copy(t.val, t.str);
	}

	void construct(T v, const char *s);
	void copy(T v, const char *s);

	T val;
	const char *str;
};

template <typename T>
void C<T>::construct(T val, const char *str)
{
	this->val = val;
	this->str = str;
}

template <typename T>
void C<T>::copy(T val, const char *str)
{
	this->val = val;
	this->str = str;
}

template <typename T>
C<T> foo(C<T> c1, C<T> &c2, const char *str, float f)
{
	return C<T>(c1.val + c2.val + f, str);
}

int main()
{
	C<int> c1(1, "debug info");
	C<int> c2(2, (const char *)0x1234); /* should not crash */

	/* 'c1' is passed by value (for each member) */
	C<int> c3 = foo(c1, c2, "passed by value", 0.001f);

	return c3.val == 3 ? 0 : 1;
}