I have been reading "Sams Teach Yourself C++ in 24 Hours". This is the code that has confused me:
#include <iostream>
class Cat
{
public:
int GetAge();
void SetAge (int age);
void Meow();
private:
int itsAge;
};
int Cat::GetAge()
{
return itsAge;
}
void Cat::SetAge(int age)
{
itsAge = age;
}
void Cat::Meow()
{
std::cout << "Meow.\n";
}
int main()
{
Cat Frisky;
Frisky.SetAge(5);
Frisky.Meow();
std::cout << "Frisky is a cat who is";
std::cout << Frisky.GetAge() << " years old.\n";
Frisky.Meow();
return 0;
}
Everything i understands except this:
int Cat::GetAge()
{
return itsAge;
}
void Cat::SetAge(int age)
{
itsAge = age;
}
void Cat::Meow()
{
std::cout << "Meow.\n";
}
if anyone can explain why the author did this it would be greatly appreciated ;)