foo

Posted LogiCoal

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
    }
};

 

以上是关于foo的主要内容,如果未能解决你的问题,请参考以下文章