fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class IntNode {
  5. public:
  6. IntNode(int value) {
  7. numVal = new int;
  8. *numVal = value;
  9. }
  10. IntNode(const IntNode& origObject) {
  11. cout << "Copying " << *(origObject.numVal) << endl;
  12. numVal = new int;
  13. *numVal = *(origObject.numVal);
  14. }
  15. ~IntNode() {
  16. delete numVal;
  17. }
  18. void SetNumVal(int val) { *numVal = val; }
  19. int GetNumVal() { return *numVal; }
  20. private:
  21. int* numVal;
  22. };
  23.  
  24. int main() {
  25. IntNode node1(3);
  26. IntNode node2 = node1;
  27.  
  28. node2.SetNumVal(5);
  29. cout << node1.GetNumVal() << " " << node2.GetNumVal() << endl;
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Copying 3
3 5