summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--constructor-test.cpp55
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;
+
+}