Cannot instantiate class

I do not see what I am doing wrong here. I am not going to show the complete creation of my main function, because I do not think it will matter.

My problem is with this class that I am creating:

class employee { //create private variables for divider string firstName; string lastName; char gender; int dependants; double annualSalary; static int numEmployees; public: Benefit1 benefit; employee() { //create default values for varaibles firstName = "not given"; lastName = "not given"; gender = 'U'; dependants = 0; annualSalary = 2000; } employee(string first, string last, char gen, int dep, double salary, Benefit1 ben) { //allow input firstName = first; lastName = last; gender = gen; dependants = dep; annualSalary = salary; benefit = ben; } } 

(Yes, Benefit1 was correctly called in the class.) My problem arises when I try to create an instance as employee2:

 employee employee2("Mary", "Noia", 'F', "5", 24000.0, benefit1); 

For some reason, my program will not allow me to put ANYTHING in the first place where the word "Mary" is. As you can see, the first instance, suppose, must be the first, so why doesn't it allow you to use anything?

+4
source share
2 answers

The problem is the fifth parameter - it expects an int , and you cheat on it with "5" . Try:

 employee employee2("Mary", "Noia", 'F', 5, 24000.0, benefit1); 
+4
source

The fourth parameter you pass in should be int : -

 employee employee2("Mary", "Noia", 'F', 5, 24000.0, benefit1); 
0
source

Source: https://habr.com/ru/post/1447328/


All Articles