开发者

conversions in C++

I have this snippet of the code:

header

class A {
private:
    int player;
public:
    A(int initPlayer = 0);
    A(const A&);
    A&开发者_如何学运维; operator=(const A&);
    ~A();
    void foo() const;
friend A& operator=(A& i, const A& member);
};

operator=

A& operator=(A& i, const A& member){   
    i(member.player);
    return i;
}

and I have row in my code:

 i = *pa1;

A *pa1 = new A(a2); at the beginning i was int

how can I fix it, thanks in advance I have an error must be non-static function


The assignment operator for a class must be a member function, not a friend.

A& operator=( const A& member){   
    this->player = member.player);
    return *this;
}

If you want to convert an A class object to an integer, provide a named conversion function such as ToInt().

As with all your questions, this could easily have been answered by reading a C++ text book. This is the last of such questions from you I will be answering.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜