I have looked around for over an hour now and I cannot find anything that is benefiting my situation. I am a beginner at C++, and this is my first attempt at splitting my code into two .cpp files and one .h file. I have yet to encounter any success. Here is my code :
#include "stdafx.h"
#include <iostream>
#include "Cat.h"
using namespace std;
int main()
{
Cat Frisky; // declare variable of type Cat, creates an object
Frisky.SetAge( 5 ); // put value INTO object
Frisky.Meow( ); // make object do something
std::cout << "Frisky is a cat who is " ;
std::cout << Frisky.GetAge() << " years old.\n " ;
Frisky.Meow( ); // make object do something
return 0;
}
// This is my cat.h
class Cat {
public:
int GetAge(); // accessor
void SetAge( int age ); // accessor
void Meow(); // general function
private:
int itsAge; // member variable
};
#include "Cat.h"
int Cat::GetAge( )
{
return itsAge;
} // end function GetAge
// set function, PUT VALUE IN to the object
void Cat::SetAge( int age )
{
itsAge = age ;
} // end function SetAge
// What do Cats do?
// What action should a Cat object perform?
void Cat::Meow( )
{
std::cout << "Meow.\n";
} // end function Meow
and here is the error messages I have been encountering for over an hour now.
1>------ Build started: Project: TestCat, Configuration: Debug Win32 ------
1> TestCat.cpp
1>TestCat.obj : error LNK2019: unresolved external symbol "public: int __thiscall Cat::GetAge(void)" (?GetAge@Cat@@QAEHXZ) referenced in function _main
1>TestCat.obj : error LNK2019: unresolved external symbol "public: void __thiscall Cat::Meow(void)" (?Meow@Cat@@QAEXXZ) referenced in function _main
1>TestCat.obj : error LNK2019: unresolved external symbol "public: void __thiscall Cat::SetAge(int)" (?SetAge@Cat@@QAEXH@Z) referenced in function _main
1>C:\Documents and Settings\Geena\Desktop\TestCat\Debug\TestCat.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have my Cat.cpp file and my Cat.h file put into the following directory : C:\Documents and Settings\Geena\Desktop\TestCat\TestCat
Just looking for the answer to get this damn program up and running already.
Thank You