开发者

conversions in C++

开发者 https://www.devze.com 2023-01-03 17:23 出处:网络
I have this snippet of the code: header class A { private: int player; public: A(int initPlayer = 0); A(const A&);

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

精彩评论

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