我有两行代码的问题。错误是:
|第 4 行|错误:在 '(' 标记| 之前需要构造函数、析构函数或类型转换
|第 50 行|错误: '!=' 标记之前的预期主表达式|
以下是代码位:
OPairType::OPairType (x=0, y=0);
和
return != (lh.x == rh.x && lh.y == rh.y);
如果您需要更多代码,请发表评论,我会提供。感谢您的任何帮助。
编辑:11/7/2013:这是标题代码:
class OPairType{
private:
int x;
int y;
public:
OPairType (int=0, int=0);
int getX() const;
int getY() const;
void setX(int);
void setY(int);
void setValues(int, int);
friend OPairType operator + (OPairType, OPairType);
friend OPairType operator - (OPairType, OPairType);
friend bool operator == (OPairType, OPairType);
friend bool operator != (OPairType, OPairType);
friend std::ostream& operator << (std::ostream&, OPairType);
这是 .cpp 代码:
#include "OPairType.h"
#include <iostream>
OPairType::OPairType (int x, int y);
int OPairType::getX() const {
return x;
}
int OPairType::getY() const {
return y;
}
void OPairType::setX(int new_x) {
x = new_x;
}
void OPairType::setY(int new_y) {
y = new_y;
}
void OPairType::setValues (int new_x, int new_y){
x = new_x;
y = new_y;
}
OPairType operator + (OPairType lh, OPairType rh){
OPairType answer;
answer.x = lh.x + rh.x;
answer.y = lh.y + rh.y;
return answer;
}
OPairType operator - (OPairType lh, OPairType rh){
OPairType answer;
answer.x = lh.x - rh.x;
answer.y = lh.y - rh.y;
return answer;
}
bool operator == (OPairType lh, OPairType rh){
return lh.x == rh.x && lh.y == rh.y;
}
bool operator != (OPairType lh, OPairType rh){
return !(lh.x == rh.x && lh.y == rh.y);
}
std::ostream& operator << (std::ostream& out, OPairType c){
out << "(" << c.x << ", " << c.y << ")";
return out;
}