Repository navigation
Expand file tree
/
Copy pathtest-main.cpp
More file actions
87 lines (72 loc) · 1.77 KB
/
Copy pathtest-main.cpp
File metadata and controls
87 lines (72 loc) · 1.77 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// Created by Evgeny Tanhilevich on 22/11/15.
//
#include <iostream>
#include <map>
#include <utility>
#include <string>
#include <vector>
using std::endl;
using std::cout;
class A;
class B;
class Test {
public:
virtual void test(A*) { cout << "Test A" << endl; }
virtual void test(B*) { cout << "Test B" << endl; }
};
class Test1: public Test {
public:
virtual void test(A*) override { cout << "Test1 A" << endl; }
virtual void test(B*) override { cout << "Test1 B" << endl; }
};
class A {
public:
virtual void test(Test& test) { cout << "A "; test.test(this); }
};
class B: public A {
public:
virtual void test(Test& test) override { cout << "B "; test.test(this); }
};
class C {
protected:
char *c;
public:
C(char _c) {
c = new char[2];
c[0] = _c;
c[1] = '\0';
}
~C() {
delete c;
}
};
typedef C* CC;
using namespace std;
class RefTest {
private:
int val;
public:
RefTest(int _val): val(_val) { cout << "Default ctor " << val << endl; }
RefTest(const RefTest& _ref_test): val(_ref_test.val) {cout << "Copy ctor" << endl;}
RefTest(RefTest&& _ref_test): val(_ref_test.val) {_ref_test.val = 0; cout << "Move ctor" << endl;}
int get_val() { return val;}
};
int main() {
A a;
B b;
Test1 test;
a.test(test);
b.test(test);
A& a1 = b;
a1.test(test);
return 0;
// map<pair<string, string>, pair<CC, CC>> m;
// m[pair<string, string>("a", "b")] = pair<CC, CC>(new C('A'), new C('B'));
// cout << m[pair<string, string>("a", "b")].first << endl;
// cout << (m[pair<string, string>("a", "c")].first == NULL) << endl;
// RefTest rt1(42);
// vector<unique_ptr<RefTest>> v;
// v.push_back(make_unique<RefTest>(rt1));
// cout << rt1.get_val() << endl;
}