65,186
社区成员




class COMPLEX
{
public:
COMPLEX operator+( COMPLEX p) {COMPLEX r; r.x = x + p.x; r.y = y + p.y; return r;}
private:
double x,y;
};
COMPLEX fun(const COMPLEX p1,const COMPLEX p2)
{
COMPLEX result;
result = p1 + p2;
return result;
}
gcc -c Complex.cpp -g -Wall
Complex.cpp: In function 'COMPLEX fun(COMPLEX, COMPLEX)':
Complex.cpp:12:19: error: passing 'const COMPLEX' as 'this' argument of 'COMPLEX COMPLEX::operator+(COMPLEX)' discards qualifiers
Compilation exited abnormally with code 1 at Sun Oct 21 21:08:42
class COMPLEX
{
public:
COMPLEX operator+( COMPLEX p) const {COMPLEX r; r.x = x + p.x; r.y = y + p.y; return r;}
private:
double x,y;
};
COMPLEX fun(const COMPLEX p1,const COMPLEX p2)
{
COMPLEX result;
result = p1 + p2;
return result;
}