hey guys! I started fiddling with C++ to expend my programming knowledge , I wrote a program (which has no use other then practicing subjects I learned )
the compiler complains that the call of overloaded "addEm" is ambiguous. I read that this probably means it can't tell which version of the function is used, yet, I don't understand how to fix it ..
Code:
#include <iostream>
using namespace std;
class cat {
private:
int age;
int height;
public:
cat();
cat(int a, int b);
~cat();
void setAge(int a);
void setHeight (int a);
int getAge(void) const;
int getHeight(void) const;
void showDetails (void);
};
int addEm (cat myCat);
int addEm (const cat& myCat);
cat::cat(){
cout<<"\ndefault constructor called\n";
age=0;
height=0;
}
cat::cat(int a, int b){
cout<<"\nregular constructor\n";
age=a;
height=b;
}
cat::~cat(){
cout<<"\ndeleting this cat\n";
}
void cat::setAge(int a) {
age=a;
}
void cat::setHeight (int a) {
height=a;
}
void cat::showDetails (void){
cout<<"this cat is "<<age<<" years old and it's height is "<<height;
}
int cat::getAge(void) const{
return age;
}
int cat::getHeight(void) const{
return height;
}
int addEm (cat myCat){
int a,b;
a=myCat.getHeight();
b=myCat.getAge();
return a+b;
}
int addEm (const cat& myCat){
int a,b;
a=myCat.getHeight();
b=myCat.getAge();
return a+b;
}
int main (void){
cat blacky(3,4);
const cat& rBlacky=blacky;
cout<<addEm(rBlacky);
cout <<"\n end the program:\n";
return 0;
}