summaryrefslogtreecommitdiff
path: root/constructor-test.cpp
blob: 2db7312f1334246af73113ba03c9df02e3c4b76b (plain)
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
#include <iostream>

/*
 *
 *
 *
 *
 */

class ConstRef {
public:
	friend void Calc_CR_Members(ConstRef &cf);
	ConstRef(int ii): i(ii), ci(ii), ri(i) {};
	void PrintMembers();
	void PrintMembersSPACE() {
		std::cout << i << " " << ci << " " << ri << std::endl;
	}
	std::ostream &PrintMembersSTREAM(std::ostream &pmcout);
	
private:
	int i;
	const int ci;
	int &ri;
};

std::ostream &ConstRef::PrintMembersSTREAM(std::ostream &pmcout) {
	pmcout << i << " " << ci << " " << ri << "\n";
	return pmcout;
}

void ConstRef::PrintMembers() {
	std::cout << i << "\n";
	std::cout << ci << "\n";
	std::cout << ri << std::endl;
}

void Calc_CR_Members(ConstRef &cf) {
	std::cout << cf.i + cf.ci + cf.ri << std::endl;
}

int main () {

	ConstRef cf(1);
	ConstRef cf2(1000);
	cf.PrintMembers();
	cf2.PrintMembers();
	cf.PrintMembersSPACE();
	cf2.PrintMembersSPACE();
	Calc_CR_Members(cf);
	Calc_CR_Members(cf2);
	cf.PrintMembersSTREAM(std::cout);
	cf2.PrintMembersSTREAM(std::cout);
	return 0;
	
}