C ++ | object pointer and array of objects

Application examples:

 1 #include<iostream>
 2 using namespace std;
 3 class Point{
 4     public :
 5         Point(){
 6         }
 7         Point(double x,double y):x_(x),y_(y){
 8         }
 9         Point &operator=(const Point &point){
10             if(&point == this)
11                 return *this;
12             
13             this->x_ = point.x_;
14             this->y_ = point.y_;
15             return *this;
16         }
17         print(){ 
18             cout<<"x:"<<this->x_<<" y:"<<this->y_<<endl; 
19         } 
20     private:
21         double x_;
22         double y_;
23 };
24 int main(){
25     Point points[4];
26     points[0] = Point(3,4);
27     points[1] = Point(5,6);
28     points[2] = Point(7,8);
29     points[3] = Point(1,8);
30     
31     //指针对象数组 
32     Point* p = points;
33     for(int i = 0; i < 4; i++)
34         (P + I) -> Print ();
 35          
36      // single pointer to the object 
37 [      Point * & Points P1 = [ 0 ];
 38 is      P1-> Print ();
 39 }

 

Guess you like

Origin www.cnblogs.com/jj81/p/11113745.html