【发布时间】:2015-01-19 17:50:40
【问题描述】:
这是我的课:
class B : public A{
private:
double r;
public:
B(){};
B(double x_, double y_, double r_){
x1 = x_; y1 = y_; r = r_;
};
~B(){};
B operator+(const B& other)
{
double result_r = r + other.r;
return B(x1, y1, result_r);
}
B operator*(const B& other)
{
double result_r = this->r * other.r;
return B(x1, y1, result_r);
}
int operator<(const B& other){
if (this->r<other.r)return 1; else return 0;
}
int operator>(const B& other){
if (this->r>other.r)return 1; else return 0;
}
};
A 类是抽象的,这就是我声明 B 的方式:
A*a = new B(10, 10, 10);
A*b = new B(20, 20, 20);
虽然(a<b) 之类的东西确实有效,但A*c=a+b; 无效。
如果我不使用指向 A 的指针,它确实有效,并且
【问题讨论】:
-
缩进你的代码。然后说用它不起作用是什么意思?例如逻辑错误或语法错误。
-
用大写字母开头的句子和使用标点符号和拼写太费力了?好像写到一半真的累了。
-
对不起,它只是在视觉 2013
error C2110: '+' : cannot add two pointers和IntelliSense: expression must have integral or unscoped enum type中返回这些错误
标签: c++ class pointers operators overloading