// By using structure :
struct complex {
float real;
float imag;
};
complex operator+(complex, complex);
main() {
complex t1, t2, t3;
t3 = t1 + t2;
}
complex operator+(complex w, complex z) {
statement 1;
statement 2;
}
// By using class :
class complex {
int real;
int imag;
public:
complex operator+(complex c) {
statement 1;
statement 2;
}
main() {
complex t1, t2, t3;
t3 = t1 + t2;
}
当使用结构时,重载函数可以接受两个参数,而同时使用类重载函数接受只有一个参数,当重载操作功能是在这两种情况下的成员函数中结构,即以及在班上。为什么会发生?结构与类
格式化您的代码,然后再问问题。 –
您应该在每行之前放置四个空格来格式化代码。您也可以选择它并单击“{}”按钮。在[Markdown编辑帮助](http://stackoverflow.com/editing-help)页面提供更多有用的提示。 –
问题是什么? – Seb