When I initialize my constructor like this :
Person::Person(std::string newName, int newAge): name(name), age(age) {}
And have..
std::string name; //and
int age;
..declared in my Person class declaration.
And use a display function:
void Person::display(){
std::cout << "Name: " << name << "." <<std::endl << "Age: " << age <<std::endl;
}
And then pass values in main:
Person Person1("Bobby", 42);
Person1.display();
it printed:
Name: . //why is it blank?
Age: 0xfjsdlfkjsdflksj //and the reference info for something.
please help!!