H
hopangtsun
Hello all,
I've got a problem on operator overloading, I don't know what's wrong
with my code.
Can anyone kindly tell me what's the problem is?
Thanks
//this is the error message I've got
eval.cpp:25: error: no match for 'operator+' in '*result_plus +
*car(iter)'
//here is my code
//Cell.cpp overload operator+
Cell* operator+ (const Cell &a, const Cell &b) const {
if (a.is_cons()){
eval(&a);
}
if (b.is_cons()){
eval(&b);
}
if (a.is_int() && b.is_int()){
int result_i = a.get_int() + b.get_int();
return new IntCell(result_i);
}
if (a.is_int() && b.is_double()){
double result_d = a.get_int() + b.get_double();
return new DoubleCell(result_d);
}
if (a.is_double() && b.is_int()){
double result_d = a.get_double() + b.get_int();
return new DoubleCell(result_d);
}
if (a.is_double() && b.is_double()){
double result_d = a.get_double() + b.get_double();
return new DoubleCell(result_d);
}
if (a.is_string() && b.is_string()){
string result_s = a.get_string() + b.get_string();
const char* result_c = result_s.c_str();
return new StringCell(result_c);
}
else {
cout << "Error: the expression is illegal" <<endl;
exit(0);
}
}
//main.cpp
Cell* result_plus = make_int(0);
iter = cdr(iter);
while (iter !=NULL){
result_plus = *result_plus +
*car(iter);
iter = cdr(iter);
}
return result_plus;
I've got a problem on operator overloading, I don't know what's wrong
with my code.
Can anyone kindly tell me what's the problem is?
Thanks
//this is the error message I've got
eval.cpp:25: error: no match for 'operator+' in '*result_plus +
*car(iter)'
//here is my code
//Cell.cpp overload operator+
Cell* operator+ (const Cell &a, const Cell &b) const {
if (a.is_cons()){
eval(&a);
}
if (b.is_cons()){
eval(&b);
}
if (a.is_int() && b.is_int()){
int result_i = a.get_int() + b.get_int();
return new IntCell(result_i);
}
if (a.is_int() && b.is_double()){
double result_d = a.get_int() + b.get_double();
return new DoubleCell(result_d);
}
if (a.is_double() && b.is_int()){
double result_d = a.get_double() + b.get_int();
return new DoubleCell(result_d);
}
if (a.is_double() && b.is_double()){
double result_d = a.get_double() + b.get_double();
return new DoubleCell(result_d);
}
if (a.is_string() && b.is_string()){
string result_s = a.get_string() + b.get_string();
const char* result_c = result_s.c_str();
return new StringCell(result_c);
}
else {
cout << "Error: the expression is illegal" <<endl;
exit(0);
}
}
//main.cpp
Cell* result_plus = make_int(0);
iter = cdr(iter);
while (iter !=NULL){
result_plus = *result_plus +
*car(iter);
iter = cdr(iter);
}
return result_plus;