Sorry to keep posting stuff.
i have written this tiny code from a book, pretty useless code but im just learning pointers.
it compiles and runs perfect, but its not giving me the right output but i dont understand why.
Code:
#include <iostream>
using namespace std;
class SimpleCat
{
public:
SimpleCat() { int ItsAge = 2; }
~SimpleCat() {}
int GetAge() const { return ItsAge; }
void SetAge(int age) { ItsAge = age; }
private:
int ItsAge;
};
int main()
{
SimpleCat * Frisky = new SimpleCat;
cout <<"Frisky is " << Frisky->GetAge() << " years old.\n";
Frisky->SetAge(5);
cout <<"Frisky is " << Frisky->GetAge() << " years old.\n";
delete Frisky;
system("PAUSE");
return 0;
}
the result of the program is...
Code:
Frisky is 3342760 years old.
Frisky is 5 years old.
Press any key to continue...
can someone just take a quick look and try to see what the problem is because i cannot find it to save my life.
cheers in advance. Reece.