diff options
author | Oskar <[email protected]> | 2024-09-26 23:22:16 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-09-26 23:22:16 +0200 |
commit | 8d61cae024eeee08b8126ee5482f211ca677dfd7 (patch) | |
tree | b2174e2b82040b0bb3e7ebace9a6e616bebf20b6 /constructor-test.cpp | |
parent | b0b9d83b2baae38be742fc21ec60bde794d3eedd (diff) |
more
Diffstat (limited to 'constructor-test.cpp')
-rw-r--r-- | constructor-test.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
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 <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; + +} |