求助:没有与参数列表匹配的构造函数
#include <iostream>#include <iomanip>
#include <cmath>
using namespace std;
class fra{
public:
fra(int s, int m);
int getx(){ return x; }
int gety(){ return y; }
int plus(fra a, fra b);
private:
int x, y;
void reduct(int m, int s);
};
fra::fra(int s, int m){
if (s*m < 0){
x = -abs(s);
y = abs(m);
}
else{
x = s;
y = m;
}
};
void fra::reduct(int m, int s){
int max, min, k, t, m1, s1;
m1 = abs(m); s1 = abs(s);
if (m1 >= s1){
max = m1;
min = s1;
}
else {
max = s1;
min = m1;
}
k = max%min;
if (k == 0)
t = min;
else
while (k){
max = min;
min = k;
t = k;
k = max%min;
}
m = m / t;
s = s / t;
cout << "Answer:" << s << "/" << m << endl;
return;
}
int fra::plus(fra a, fra b){
int m, s;
if (a.gety() == 0 || b.gety() == 0){
cout << "ERROR!" << endl;
return 0;
}
m = a.gety()*b.gety();
s = (a.getx()*b.gety()) + (b.getx()*a.gety());
reduct(m, s);
return 0;
}
int main(){
int p, q,k,l;
cin >> p >> q >> k >> l;
fra a(p,q), b(k,l);
fra plus(a, b);//此处a下边提示错误“没有与参数列表匹配的构造函数"fra::fra"实例,参数类型为:(fra,fra)”
return 0;
}