foo

struct Point3D{
    float* Coordinates;

    Point3D(float x, float y, float z){
        Coordinates= (float*)malloc(3* sizeof(float));
        *(Coordinates+0)=x;
        *(Coordinates+1)=y;
        *(Coordinates+2)=z;
    }

    Point3D(const Point3D& p){
        Coordinates= (float*)malloc(3* sizeof(float));
        memcpy(Coordinates,p.Coordinates,3* sizeof(float));
    }

    Point3D& operator = (const Point3D& p){
        if (this==& p)
            return *this;
        memcpy(Coordinates,p.Coordinates,3* sizeof(float));
        return *this;
    }

    float operator[] (const int i){
        return *(Coordinates+i);
    }

    float operator[] (const int i) const{
        return *(Coordinates+i);
    }

    ~Point3D(){
        free(Coordinates);
        Coordinates= nullptr;
    }
};

 

posted @ 2018-05-20 18:42  fndefbwefsowpvqfx  阅读(133)  评论(0编辑  收藏  举报