I have encountered the problem of not being able to pass a char arraray as a parameter into my class, I get the error "prototype for "Employee::Employee(char*,int,char*)' does not match any in class 'Employee' Employee::Employee( char n[20], int a, char j[30]). Thank you in advance for your support.
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
/*No need for passing arguments into the functions since they can
* call the variables declared in the private access specifier. */
class Employee
{
private:
char Name[20], Jobtitle[30]; //Why not working ?
int Age;
public:
Employee(char, int, char);
char* getname(); /*Could having the name of the function the same as the variables cause a problem ? Yes it will*/
int getage();
char* getjobtitle();
};
#endif // EMPLOYEE_H
Look at your class definition: Employee(char, int, char);
Do you realize that this is defining a constructor that takes a single char, an int, and another single char?
Now look at your constructor implementation: Employee::Employee( char n[20], int a, char j[30] )
Do you realize that this is implementing a constructor that takes a char* an int and another char*?
By the way remember that in a function definition char n[20] is the same as char n[], or char* n.
And lastly, for now, you should be using something like strcpy() to copy those C-strings, or better yet save yourself a bunch of headaches and start using C++ std::string instead of the horrible C-strings.
Hi jlb, thanks for your reply again. But I do not understand my constructor takes a char pointer if I have written Employee::Employee( char n[20], int a, char j[30] ) .
Is there something I am still missing in my constructor ? Or a concept I have mis-understood ?
Is it just because I am using char that I get these issues ?
Very importantly, if I want to pass an array, let's say of type int, is there something else I have to do to not get the same (or other) errors ?
Since I cannot post an image or file in here I will post my main.cpp code and give a link to download the print error screen and my full file containing the .pro plus all the other files.