stuff - mystuff.getNumber = 2...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <string> using namespace std; u class Stuff { private: int number; string label; public: Stuff (int num=5, string str="hello") : number(num), label(str) { cout << "Constructor" << endl; } cout << "Copy Constructor" << endl; number= original.number; label= original.label; } return number; } return label; } cout << "Assignment Operator" << endl; label= original.label; number= original.number; return *this; } ~Stuff() { cout << "Destructor" << endl; } }; } Stuff g(Stuff mystuff) { cout << "inside g" << endl; mystuff.getLabel() = "last label";
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: mystuff.getNumber() += 2; cout &amp;lt;&amp;lt; &amp;quot;leaving g&amp;quot; &amp;lt;&amp;lt; endl; return mystuff; } Stuff&amp;amp; f(Stuff value1, Stuff&amp;amp; value2) { cout &amp;lt;&amp;lt; &amp;quot;inside f&amp;quot; &amp;lt;&amp;lt; endl; Stuff temp(value1); value2= g(temp); cout&amp;lt;&amp;lt; &amp;quot;leaving f&amp;quot; &amp;lt;&amp;lt; endl; return value2; } int main(){ Stuff a; Stuff *b = new Stuff(a); Stuff c(36, &amp;quot;goodbye&amp;quot;); b-&amp;gt;getNumber() = 42; a.getLabel() = &amp;quot;new label&amp;quot;; a= f(*b,c); ///cout &amp;lt;&amp;lt; &amp;quot;a is &amp;quot; &amp;lt;&amp;lt; a.getNumber() &amp;lt;&amp;lt; &amp;quot; and &amp;quot; &amp;lt;&amp;lt; a.getLabel() &amp;lt;&amp;lt; endl; ///cout &amp;lt;&amp;lt; &amp;quot;b is &amp;quot; &amp;lt;&amp;lt; (*b).getNumber() &amp;lt;&amp;lt; &amp;quot; and &amp;quot; &amp;lt;&amp;lt; (*b).getLabel() &amp;lt;&amp;lt; endl; ///cout &amp;lt;&amp;lt; &amp;quot;b is &amp;quot; &amp;lt;&amp;lt; c.getNumber() &amp;lt;&amp;lt; &amp;quot; and &amp;quot; &amp;lt;&amp;lt; c.getLabel() &amp;lt;&amp;lt; endl; return 0; }...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

stuff - mystuff.getNumber = 2...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online