From 8d61cae024eeee08b8126ee5482f211ca677dfd7 Mon Sep 17 00:00:00 2001 From: Oskar Date: Thu, 26 Sep 2024 23:22:16 +0200 Subject: more --- constructor-test.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 constructor-test.cpp diff --git a/constructor-test.cpp b/constructor-test.cpp new file mode 100644 index 0000000..2db7312 --- /dev/null +++ b/constructor-test.cpp @@ -0,0 +1,55 @@ +#include + +/* + * + * + * + * + */ + +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; + +} -- cgit v1.2.3