找到你要的答案

Q:no instance of constructor “AcademicStaff::AcademicStaff” matches the argument list

Q:“academicstaff构造函数没有实例::academicstaff”匹配的参数列表

I declared

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

constructor for initiliazing.

When I called the functiion in main I got an error

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

Calling Function :

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

我宣布

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

构造函数initiliazing。

当我打电话的功能主要有错误

 "  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);
answer1: 回答1:

You need to call the function with AcademicStaff headOdDepartment(staffID, firstName, lastName, telNo, address, email, annualSalary, title, status); You're sending the first element if you send *charArray.

You need to call the function with AcademicStaff headOdDepartment(staffID, firstName, lastName, telNo, address, email, annualSalary, title, status); You're sending the first element if you send *charArray.

answer2: 回答2:

Your constructor accepts pointers to strings. See below

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

but when you are calling constructor you are dereferencing the pointers using * e.g *firstName. See

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

Remove the dereferencing and use the following code

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

构造函数接受字符串的指针。看下面

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

但是当你调用构造函数你解引用指针使用*你*的名字。看到

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

删除引用和使用下面的代码

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