Hello,
I have a class that I have written. But have a problem with a compile error. Underfined reference to 'Mammal::GetAge() const'
I have put my class into a seperate file called Mammal.hpp.
The implementation is called Mammal.cpp.
I have another file for testing the application called main.cpp
I have included the Mammal.hpp header in my Mammal.cpp file.
I am wondering if this is the correct way to do this?
Many thanks,
Mammal.hpp - file
Code:
#include <iostream>
class Mammal
{
public:
Mammal():itsAge(10){ std::cout << "Mammal constructor" << std::endl; }
virtual ~Mammal(){ std::cout << "Mammal distructor" << std::endl; }
void Move() const {std::cout << "Mammal move one step" << std::endl;}
void Move(int) const {std::cout << "Mammal move a specified number of steps" << std::endl; }
void GetAge() const;
void GetWeight() const;
virtual void Speak() const { std::cout << "Mammal speak" << std::endl; }
protected:
int itsAge;
int itsWeight;
};
void Mammal::GetWeight() const
{
std::cout << "Get Weight: " << itsWeight << std::endl;
}
Mammal.cpp - file
Code:
#include "Mammal.hpp"
void Mammal::GetAge() const
{
std::cout << "Age: " << itsAge << std::endl;
}
Main.cpp - file
Code:
#include "Mammal.hpp"
int main()
{
std::cout << "Hello World" << std::endl;
Mammal myMammal;
myMammal.Move();
myMammal.GetAge();
return 0;
}