| | | | | |

Copy Constructor 1

  • There are two common situations when an object must be copied implictly:
    1. When an object is passed to a function as a value parameter
    2. When an object is returned by a function as a value
  • IntArray Fun (IntArray a);  // prototype
    ...
    IntArray a,b;
    b = Fun(a);    // copy of argument "a" made when function is called 
                   // copy of return value made as function returns
    
  • In addition to at least one where objects are copied explicitly:
    1. When an object is initialized in a declaration
  • IntArray a;
    ...
    IntArray b(a); // explicit call to copy constructor - make "b" a copy of "a"
    

| | Top of Page | 6. C++ Classes Part 2: Advanced Features - 3 of 22