就是一个拷贝构造函数,所有的成员都赋值一遍就行了。如果有指针,需要拷贝内存;如果有类成员变量,该类需要有拷贝构造函数或赋值操作符。

解决方案 »

  1.   

    我知道,我也在代码上做了一些修改,现在代码是这样:
    struct Position
    {
    float x;
    float y;
    float z;
    };struct Color
    {
    float R;
    float G;
    float B;
    };class Particles
    {
    public:

    Particles(float x, float y, float z);
             Particles(const Particles &p)
    void Render();
    bool dead;
    private:
    Position Pos;
    Color Col;
    float speed;
    float speed_acc;
    float alpha;
    float alpha_dec;
    float size;
    };
    //数据更新 if(fps==0) fps=30;
     Particles oldParticle( *this );//(这句话是调用oldParticle的属性值,也就是在particles那里拷贝过来的属性值)
    speed+=speed_acc;
    Pos.y +=speed;
    alpha-=alpha_dec;
    size-=0.05f*(30/fps); Pos.x +=-Pos.x/30.0f;
    Pos.z +=-Pos.z/30.0f; if(alpha<=0.0f) dead=true;
    }Particles::Particles(float x, float y, float z)
    {
    Pos.x = x;
    Pos.y = y;
    Pos.z = z;
    Col.R = 1.0f;
    Col.G = 1.0f;
    Col.B = 0.8f;
    speed = 0.2f;
    speed_acc = GetRandom(0.013f, 0.015f);
    alpha = 1.0f;
    alpha_dec = GetRandom(0.033f, 0.03301f);
    size=4.0f;
    dead = false;
    }
      Particles::Particles(const Particles &p){
    this->Pos.x = p.Pos.x;
    this->Pos.y = p.Pos.y;
    this->Pos.z = p.Pos.z;
    this->Col.R = p.Col.R;
    this->Col.G = p.Col.G;
    this->Col.B = p.Col.B;
    this->speed = p.speed;
    this->speed_acc = p.speed_acc;
    this->alpha = p.alpha;
    this->alpha_dec = p.alpha_dec;
    this->size = p.size;
    this->dead = p.dead;
    }调试不出来,不知道还有哪里不对,你帮我看下吧,谢谢