I'm playing around with some basic C++ and I'm having trouble with a class I'm writing. Just about everything works fine, but when I create the Cat class the constructors don't define the data members and it is just empty values where they should be.
#include "stdafx.h"
#include <iostream>
#include <string>
#include "cat.cpp"
usingnamespace std;
int _tmain(int argc, _TCHAR* argv[])
{
// Create 2 cats
Cat jack("Jack", 1);
Cat max("Max", 1);
// Have each meow
jack.GetName();
cout << " says ";
jack.Meow();
cout << endl;
max.GetName();
cout << " says ";
max.Meow();
cout << "\n\n";
// Have each cat say their names and ages
cout << "Hi, my name is ";
jack.GetName();
cout << " and I am ";
jack.GetAge();
cout << " years old!" << endl;
cout << "Hi, my name is ";
max.GetName();
cout << " and I am ";
max.GetAge();
cout << " years old!\n\n";
// Have each cat meow again and say goodbye
jack.GetName();
cout << " says ";
jack.Meow();
cout << " and goodbye.\n";
max.GetName();
cout << " says ";
max.Meow();
cout << " and goodbye.\n\n";
system("pause");
return 0;
}
but when I create the Cat class the constructors don't define the data members and it is just empty values where they should be.
You mean initialize.
the functions GetName() and GetAge() just return the values as they're supposed to do. So they don't print them to the screen. To print them you need cout like so:
1 2
cout << "Hi, my name is ";
cout << jack.GetName();