I am working from the book SAMS teach yourself C++ and I am encountering the following problem while trying to use codeblocks to build the following code.
I presume the error on line 22 in main.cpp has to do with the errors in include\Cat.h but the other one one line 25 I have no idea about what is causing it as well as the 2 errors in include\Cat.h.
Hoped someone here could help me out.
main.cpp
Code:
// Demonstration of inline functions and inclusion of header files.
// Be sure to include the header files!
#include "include\Cat.h"
Cat::Cat(int initialAge) // Constructor
{
itsAge = initialAge;
}
Cat::~Cat() // Deconstructor
{
}
// Create a cat, set its age, have it meow, tell us its age, then make it meow again
int main()
{
Cat Frisky(5);
Frisky.Meow();
std::cout << "Frisky is a cat who is ";
std::cout << GetAge() << " years old.\n";
Frisky.Meow();
Frisky SetAge (7);
std::cout << "Now Frisky is ";
std::cout << GetAge() << " years old.";
return 0;
}
Errors
Line 22, 'GetAge' was not declared in this scope
Line 25, expected ';' before 'SetAge'
include\Cat.h
Code:
#include<iostream>
class Cat
{
public:
Cat(int initialAge);
~Cat();
int GetAge const { return itsAge;} // Inline!
void SetAge(int age) { itsAge = age;} // Inline!
void Meow() const { std::cout << "Meow!\n";} // Inline!
private:
int itsAge;
};
Errors
Line 8, expected ';' before 'const'
Line 9, expected ';' before 'void'