C++ can';t实例化类

C++ can';t实例化类,c++,class,instantiation,C++,Class,Instantiation,我看不出我做错了什么。我不打算展示我的主要功能的完整创建,因为我认为这无关紧要 我的问题与我创建的这个类有关: class employee { //create private variables for divider string firstName; string lastName; char gender; int dependants; double annualSalary; static int numEmployees;

我看不出我做错了什么。我不打算展示我的主要功能的完整创建,因为我认为这无关紧要

我的问题与我创建的这个类有关:

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;
    }
}
(是的,Benefit1在类中被正确调用。)当我尝试将其实例化为employee2时,我的问题出现了:

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

出于某种原因,我的程序不允许我把任何东西放在单词“玛丽”的第一个位置。正如您所看到的,第一个实例被假定为字符串优先,那么为什么它不允许使用任何东西呢?

问题在于第五个参数-它需要一个
int
,您正在处理它
“5”
。尝试:

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

您要传递的第四个参数必须是
int
:-

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

在Ctor中,“5”不应该是5吗,因为Ctor需要一个int?谢谢,真不敢相信我错过了。我不知道为什么我的系统突出显示了“玛丽”。我记得我为什么犯了那个错误。我的课堂作业要求我写一些有趣的家眷和年表。数字必须作为字符串输入,然后转换为适当的类型。混乱和不必要,是的,但我想它教我们如何使用转换。