I am working with virtual functions and run-time polymorphism. The issue I am having, which its preventing me from doing anything else with this program, is my compiler is throwing an error when I try and make the constructor for SalariedEmployee claiming that there is no base constructor for employee. I created the constructor at the bottom for employee and it still throws an error. I am looking for help with constructor creations for each class. Not sure at this point, if its my mistake or my compiler is not set up properly?
Always something relatively simple, thank you. Since all the employee class member functions are public I should be able to use those to initialize the SalariedEmployee objects?
If I declare object SalariedEmployee emp1();
how do i go about assigning values to each member function from here?
Shouldn't it be emp1.fullName ="Insert Name"?
Since all the employee class member functions are public I should be able to use those to initialize the SalariedEmployee objects?
Yes, although best practice is not to make the member variables public. By having the member variables public, you open yourself up to allowing them to be changed anywhere in your program rather than controlling access through member functions of your class.
If I declare object SalariedEmployee emp1();
Your declaration of emp1 should not have the ().
Your declaration of emp1 should pass a single argument (ID) since SalariedEmployee has only a single constructor that requires an int.
Shouldn't it be emp1.fullName ="Insert Name"?
That works since your member variables are public.
When i remove the (); from my SalariedEmployee object is get another warning about how I don't have a constructor for this class. I thought employee(id) was assumed through Salaried Employee since we initialized it to the base class.
No. SalariedEmployee has a constructor that takes an int, and passes it through to the Employee constructor.
If you try and instantiate a SalariedEmployee object without passing an int into the constructor, how could the compiler possibly know what value to pass to the Employee constructor?
EDIT:
And:
SalariedEmployee emp1();
does not define an object. It actually declares a function called emp1(), that returns a SalariedEmployee. That catches a lot of people out :)