• 08-13-2003
RealityFusion
I started learning class's and I made this one program and it had so many errors on it. I managed to get them down to 2. I can't seem to figure out what the problem is though. Can anyone help me out ?
Code:

#include <iostream>
using namespace std;

class Cat
{
public:
int setAge(int age);
int setWeight();
int getAge();
int getWeight();
void Meow();
private:
int itsAge;
int itsWeight;
};
//=====Starting of Age=========//
int Cat::setAge(int age)
{
itsAge = age;
}
int Cat::getAge()
{
return itsAge;
}
//=========End of Age===========//

//=========Meow()=============//
void Cat::Meow()
{
cout <<"Meow" <<endl;
}
//======End of Meow============//

//======Starting Weight==========//
int Cat::setWeight(int weight)
{
itsWeight = weight;
}
int Cat::getWeight()
{
return itsWeight;
}
//==========End of Weight===========//

//===-=-=-=-=-=-=-=-=-Starting Main=-=-=-=-=-=-=-=-=//
int main()
{
int age,weight;

cout <<"How old is your cat?" <<endl;
cin >>age;
cout <<"How much does your cat weigh in pounds?" <<endl;
cin >>weight;

Cat Frisky;
Frisky.setAge(age);
Frisky.Meow();
cout <<"The cat is " << Frisky.getAge() <<" years old." <<endl;
Frisky.Meow();
Frisky.setWeight(weight);
cout <<"The cat is " <<Frisky.getWeight() <<" pounds." <<endl;
Frisky.Meow();
return 0;
}

• 08-13-2003
PJYelton
Its because your setWeight function is listed as having no parameters in the class declaration, but in the function definition it has the parameter int weight.

By the way, in the future if you have problems like this, write down the error your compiler gives as well as the code. Many people won't spend the time looking at the code trying to figure out on their own what the bug is.
• 08-13-2003
RealityFusion
Ok, thanks for the tip! The code worked too! :D
• 08-13-2003
funkydude9
Also, setAge needs to be void because your're not returning anything, and so does setWeight.
Code:

#include <iostream>
using namespace std;

class Cat
{
public:
void setAge(int age);
void setWeight(int weight);
int getAge();
int getWeight();
void Meow();
private:
int itsAge;
int itsWeight;
};
//=====Starting of Age=========//
void Cat::setAge(int age)
{
itsAge = age;
}
int Cat::getAge()
{
return itsAge;
}
//=========End of Age===========//

//=========Meow()=============//
void Cat::Meow()
{
cout <<"Meow" <<endl;
}
//======End of Meow============//

//======Starting Weight==========//
void Cat::setWeight(int weight)
{
itsWeight = weight;
}
int Cat::getWeight()
{
return itsWeight;
}
//==========End of Weight===========//

//===-=-=-=-=-=-=-=-=-Starting Main=-=-=-=-=-=-=-=-=//
int main()
{
int age,weight;

cout <<"How old is your cat?" <<endl;
cin >>age;
cout <<"How much does your cat weigh in pounds?" <<endl;
cin >>weight;

Cat Frisky;
Frisky.setAge(age);
Frisky.Meow();
cout <<"The cat is " << Frisky.getAge() <<" years old." <<endl;
Frisky.Meow();
Frisky.setWeight(weight);
cout <<"The cat is " <<Frisky.getWeight() <<" pounds." <<endl;
Frisky.Meow();
return 0;
}