Replication of the constructor

#include <the iostream>
 the using  namespace STD; 

class Point {
 public : 
    Point ( int XX = 0 , int YY = 0 ) { // if no initial value constructor passed in, default = 0 XX, YY = 0 
        X = XX , Y = YY; 
    } 
    Point (Point & P);
     int getX () {
         return X; 
   } 
   int getY () {
        return Y; 
   } 
Private :
     int X, Y; 
}; 

Point :: Point (Point & P)
{ 
    X = PX; 
    Y = Py; 
} 

void F (Point P) 
{ 
    COUT << p.getx () << endl; 
} 
Point FF () 
{ 
    Point C ( . 3 , . 4 );
     return C; 
} 
int main ( ) { 
    Point a ( . 1 , 2 ); 
    Point B (a); // Point B = a;.. 1 with a further object class to initialize the class object 
    COUT << b.getx () << endl; 
    F (a); // 2. when an object class as an argument of the function, the copy constructor call 
    B = FF (); 
    COUTB.gety << () << endl; // 3. When the return value of a function of class type, the copy constructor calls 
    return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/LLLAIH/p/11030209.html