I keep getting various errors while trying to pass a varriable through my second constructor

I need help fixing the second constructor so i can pass a a name trough it i know the call is right so its an issue with the second employee constructor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

class Employee
{
public:
  Employee()
  {
  	char person[]="None";
  	strcpy (name, person);
  	idNum=1000;
  	salary=0;
  };
  Employee(const char *x, int id, double sal)
  {
	strcpy (name, *x);
  	idNum=id;
  	salary=sal;
  };

    
  void printEmp()
  	{
  		cout<<"Employee: ";
  		for (int x=0;x<26;x++)
  		{
  			cout<<name[x];
		}
  		cout<<"ID: "<<idNum;
  		cout<<"Salary: "<<salary;
  	};
  void increaseSalary( double more)
  {
	if (more>0)
	{
		salary=salary+more;
	}
	else
	{
		cout<<"Error: the salary cannot be increased";
	}
  };

  void setIDnum( int newIDnum)
  {
  	if (newIDnum<1000||newIDnum>9999999)
  	{
		cout<<"Error: the new identification number is invalid. It will be ste to 1000";
  		idNum=1000;
	}
	else
	{
		idNum=newIDnum;
	}
  };
  void setSalary( double newSalary)
  {
  	if(newSalary<=0)
  	{
  		cout<<"Error: the passed in salary is invalid. The salary will be set to 0.00";
  		salary=0.00;
	}
	else
	{
		salary=newSalary;
	}
  };

  int getIDnum()
  {
  	return idNum;
  };
  double getSalary()
  {
  	return salary;
  };

private:
  char name[25];
  int idNum;
  double salary;
};


int main()
{
Employee e1= Employee( "Matthew Lyon", 1704663, 678367732.40);
What exactly is the error?

You may want to compare line 21 to line 15. One is correct the other is incorrect, see if you can figure out the problem.


strcpy (name, *x);

strcpy takes two char-pointers. name is a char pointer, but *x isn't a char-pointer.

Also, why use char arrays? Just use a string.
Last edited on
33 18 C:\Users\lyonm513\Documents\Program 8.cpp [Error] invalid conversion from 'char' to 'const char*' [-fpermissive]
thats the error i keep getting
Yes. We already told you what the problem is. The function you're trying to use takes two parameters. BOTH parameters must be char-pointers. *x is NOT a char-pointer.

Is that clear? You must pass a parameter that IS a char-pointer, but the parameter *x is NOT a char-pointer.

The parameter is meant to be a certain type, but you are passing something that is NOT that type.

Do you understand how, for example, an int is not a string? This is a similar situation; a char is NOT a char-pointer.

Topic archived. No new replies allowed.