constructor/this pointer help

Hello. Curious as to why I am getting the same output of:
First name: (blank)
Last name: (blank)
Zip code: (blank)

when using the default value of "X" and when using the info supplied?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 #include<iostream>
#include<string>
using namespace std;

class Person
{
private:
	string firstName;
	string lastName;
	string zipCode;

public:
	Person(string = "X", string = "X", string = "X"); //constructor to set values to X if no arguments are supplied
	void displayInfo();

};

Person::Person(string firstName, string lastName, string zipCode)
{
	this->firstName = firstName;
	this->lastName = lastName;
	this->zipCode = zipCode;
}

void Person::displayInfo()
{
	cout << "********** "<< endl;
	cout << "First name: " << endl;
	cout << "Last name: "<< endl;
	cout << "Zip code: "<< endl;

}
int main()
{
	Person noDetails;			//Person object w/ default values "X"
	noDetails.displayInfo();

	Person details("Billy", "Enforcee", "77177");			//Person object with given values
	details.displayInfo();

	system("pause");
	return 0;

}
In Person::displayInfo():
cout << "First name: " << firstName << endl;
Last edited on
doh!! Thanks. Looked over that quite a few times. Me so tired. Thanks again
Topic archived. No new replies allowed.