【问题标题】:no instance of constructor "AcademicStaff::AcademicStaff" matches the argument list没有构造函数“AcademicStaff::AcademicStaff”的实例与参数列表匹配
【发布时间】:2015-05-02 08:32:18
【问题描述】:

我声明了

AcademicStaff(int, char *, char *, int , char *, char *,int, char *,char *) 

用于初始化的构造函数。

当我在 main 中调用函数时出现错误

 "  2   IntelliSense: no instance of constructor "AcademicStaff::AcademicStaff" matches the argument list
            argument types are: (int, char, char, int, char, char, int, char, char)".

调用函数:

AcademicStaff headOdDepartment(staffID, *firstName, *lastName, telNo, *address, *email, annualSalary, *title, *status);
myDepartment.setheadOfDepartment(headOdDepartment);

【问题讨论】:

  • 我要firstName, lastName, address, email, titlestatus,都是char*。那么是什么让你在调用构造函数时取消引用它们?
  • 嗯,是的。您传递给它的参数 (int, char, char, int, char, char, int, char, char)(int, char *, char *, int, char *, char *, int, char *, char *) 不同

标签: c++ intellisense


【解决方案1】:

您需要使用AcademicStaff headOdDepartment(staffID, firstName, lastName, telNo, address, email, annualSalary, title, status); 调用该函数 如果您发送*charArray,您将发送第一个元素。

【讨论】:

    【解决方案2】:

    您的构造函数接受指向字符串的指针。见下文

    AcademicStaff(int, char *, char *, int , char *, char *,int, char *,char *) 
    

    但是当您调用构造函数时,您正在使用 * 例如 *firstName 取消引用指针。见

    AcademicStaff headOdDepartment(staffID, *firstName, *lastName, telNo, *address, *email, annualSalary, *title, *status);
    

    删除解引用并使用以下代码

    AcademicStaff headOdDepartment(staffID, firstName, lastName, telNo, address, email, annualSalary, title, status);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-02
      • 2016-03-05
      • 1970-01-01
      • 2013-10-29
      • 2021-12-10
      • 2014-09-09
      • 1970-01-01
      • 2019-03-27
      相关资源
      最近更新 更多