Using Constructor from a Base Class

Hello, I am doing a program that requires me to use the base constructor of a class when instantiating the derived class and just cannot get a hold on this. Please refer to the code below:
Base Class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class PersonData
{
public:
	PersonData();
	PersonData(string,string,string,string,string,string,string);

private:
	string lastName;
	string firstName;
	string address;
	string city;
	string state;
	string zip;
	string phone;
};


Derived Class:

1
2
3
4
5
6
7
8
9
10
class CustomerData: public PersonData
{
public:
	CustomerData();

	CustomerData(int, bool);
private:
	int customerNumber;
	bool mailingList;
};


PersonData.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "PersonData.h"

PersonData::PersonData(){
	lastName="";
		firstName="";
		address="";
		city="";
		state="";
		zip="";
		phone="";
}

PersonData::PersonData(string ln, string fn, string adrs,string c,string s,string z,string phn)
{
	lastName = ln;
		firstName = fn;
		address = adrs;
		city = c;
		state = s;
		zip = z;
		phone = phn;
}


CustomerData.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
#include "CustomerData.h"


CustomerData::CustomerData()
{
	customerNumber=0;
	mailingList=false;
}

CustomerData::CustomerData(int cn, bool ml){
	customerNumber=cn;
	mailingList=ml;
}


Nothing too fancy. I need to create an object with the CustomerData class that uses the constructor from PearsonData that takes the 7 arguements. Is there anyway this can be done?
This:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class SuperClass
{
    public:

        SuperClass(int foo)
        {
            // do something with foo
        }
};

class SubClass : public SuperClass
{
    public:

        SubClass(int foo, int bar)
        : SuperClass(foo)    // Call the superclass constructor in the subclass' initialization list.
        {
            // do something with bar
        }
};


Was taken from here:
http://stackoverflow.com/questions/120876/c-superclass-constructor-calling-rules
Thanks a lot. I've seen this but I still don't quite understand how to implement it in my program. The description asks to put the constructor definitions in the cpp files and the headers in the .h files.

I've tried different combinations of the above and none of it seems to work. Any suggestions?
The derived constructor needs to have enough arguments to call the parent constructor plus enough arguments to handle its own constructor.
In your case:
1
2
3
4
5
6
CustomerData::CustomerData(int cn, bool ml, string ln, string fn, string adrs, string c, string s, string z, string phn)
	: PersonData(ln, fn, adrs, c, s, z, phn)
{
	customerNumber=cn;
	mailingList=ml;
}
Topic archived. No new replies allowed.