Hi strife,
Here is a little improvement:
1 2 3 4 5 6 7 8
|
class Employee {
public:
Employee(); // Default 0 argument constructor
Employee(float s; string n) : // custom constructor with initialiser list
sal(s),
name(n){} // no need for any code here
//rest of class here
|
The above looks similar, but is better. When an object of a class type is created, it's member variables are initialised by default before the code in the constructor is run. If the code initialises values by assignment, then this is a waste because it is essentially being done twice. If the constructor has an initialisation list as above, then member variables are only initialised once. Initialisation of base class constructors can be done from here as well.
Btw, I would recommend you have more meaningful names for your variables : s, n sal are not particularly good IMO. An exception to naming might be for mathematical equations, or when documentation one is working from has a particular format, or one wants to make the variable names similar to the documentation. For example: r = sqrt(x
2 + y
2)
Another example is if documentation has Greek letters, so names like RAlpha would be OK.
Hope all is well :+)
EDIT:
One can still use an initialiser list even though there are no arguments for the constructor, so this would set the default values you want.