I'm trying to make a simple person class with a name, location, sex, and age with a constructor and a method for printing the info out. I'm getting the following warning:
Warning C26495 Variable 'person::age' is uninitialized. Always initialize a member variable (type.6
It looks like I have it initialized. Also, when I run the code nothing prints because nothing is saved in my object. Here is the code:
#include<iostream>
using namespace std;
class person {//class (public: makes it usable within program)
public:
string name;
string location;
string sex;
int age;
person(string name, string location, string sex, int age) {//constructor
name = name;
location = location;
sex = sex;
age = 0;
}
void printinfo() {
cout << "name: " << name << endl;
cout << "location: " << location << endl;
cout << "sex: " << sex << endl;
cout << "age: " << age << endl;
}
};
int main()
{
person person1 ("James", "NYC", "Male", 0);
person1.printinfo();
system("pause>0");
}