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;
    }
};

猜你喜欢

转载自www.cnblogs.com/Searchor/p/9064178.html
foo
今日推荐