You are having a problem with calling the base class constructor...
Read my this post in your old thread...
17 Replies - 472 Views - Last Post: 11 January 2013 - 11:11 AM
#17
Re: Why is my variable undefined
Posted 11 January 2013 - 10:54 AM
A constructor function is a function that runs when a class object/instance is created.
You are creating objects here :
the data is meaningless at this point, basically this constructor is not needed.
So all you need is
When the user has input the data you can use your set functions.
You are creating objects here :
219 SalariedEmployee emp1(name, soc,
net, wage, hrs, dept);
220 Administrator adm1(admtitle, resp,
sup, sal);
the data is meaningless at this point, basically this constructor is not needed.
So all you need is
219 SalariedEmployee emp1; 220 Administrator adm1;
When the user has input the data you can use your set functions.
adm1.Setname(name); adm1.Settitle(admtitle);
This post has been edited by #define: 11 January 2013 - 10:55 AM
#18
Re: Why is my variable undefined
Posted 11 January 2013 - 11:11 AM
If you want to pass data using the a constructor you could try :
although, it is possible and useful to use a base class constructor (there may be calculations to perform etc).
Administrator(string n, string sc, double np,
double w, int h, string d,
string t, string r, string sp,
double sa )
// initialization list
: name(n), ssn(sc), netPay(np),
wageRate(w), hours(h),
department(d),
title(t), responsi(r),
super(sp), salary(sa)
{
}
although, it is possible and useful to use a base class constructor (there may be calculations to perform etc).
Administrator(string n, string sc, double np,
double w, int h, string d,
string t, string r, string sp,
double sa )
// initialization list
// using a base class constructor
: SalariedEmployee(n, sc, np,
w, h, d) ,
title(t), responsi(r),
super(sp), salary(sa)
{
}
This post has been edited by #define: 11 January 2013 - 11:12 AM
|
|

New Topic/Question
Reply




MultiQuote




|