Why is my variable undefined

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 955 Views - Last Post: 11 January 2013 - 11:11 AM Rate Topic: -----

#16 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: Why is my variable undefined

Posted 11 January 2013 - 09:13 AM

You are having a problem with calling the base class constructor...

Read my this post in your old thread...
Was This Post Helpful? 0
  • +
  • -

#17 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1347
  • View blog
  • Posts: 4,642
  • Joined: 19-February 09

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 :

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

Was This Post Helpful? 0
  • +
  • -

#18 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1347
  • View blog
  • Posts: 4,642
  • Joined: 19-February 09

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 :


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

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2