473,416 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Error in program. cannot convert from 'char []' to 'char [10]'

I get 4 of those errors. in the same spot. I'll show my parent class,
child class, and my driver.

All that is suppose to happen is the user enters data and it uses
parent/child class to display it.

here is the 4 errors.

c:\C++\Ch15\Employee.h(29): error C2440: '=' : cannot convert from
'char []' to 'char [6]'
c:\C++\Ch15\Employee.h(27): error C2440: '=' : cannot convert from
'char []' to 'char [21]'
c:\C++\Ch15\Employee.h(28): error C2440: '=' : cannot convert from
'char []' to 'char [13]'
c:\C++\Ch15\Employee.h(30): error C2440: '=' : cannot convert from
'char []' to 'char [10]'

this is the part that it don't like in my parent class.

Employee(char n[21], char s[13], char e[6], char h[10]) //constructor
{
name = n;
ssn = s;
empNumber = e;
hire = h;
}

Here is my parent class.

//specification file for the Employee class.
#ifndef EMPLOYEE_H
#define EMPLOYEE_H

class Employee
{
private:
char name[21];
char ssn[13];
char empNumber[6];
char hire[10];
//char name;
//char ssn;
//char empNumber;
//char hire;
public:
//Employee() //default contrusctor
//{
// name =' ';
// ssn =' ';
// empNumber=' ';
// hire=' ';
//}

Employee(char n[21], char s[13], char e[6], char h[10]) //constructor
{
name = n;
ssn = s;
empNumber = e;
hire = h;
}

~Employee() //destructor
{
}

char getName()
{
return name[21];
}
char getSSN()
{
return ssn[13];
}
char getEmpNumber()
{
return empNumber[6];
}
char getHire()
{
return hire[10];
}
};
#endif

**here is my child class

//specification file for the EmployeePay class
#ifndef EMPLOYEEPAY_H
#define EMPLOYEEPAY_H
#include "Employee.h"

class EmployeePay: public Employee
{

protected:
float anPay;
float moPay;
int depend;
public:
//derived class contructor
EmployeePay(char n, char s, char e, char h, float an, float mo, int
de) : Employee(n, s, e, h)
{
anPay = an;
moPay = mo;
depend = de;
}

~EmployeePay() //destructor
{
}
float getAnPay()
{
return anPay;
}
float getMoPay()
{
return moPay;
}

int getDepend()
{
return depend;
}

};
#endif

**here is my driver

//this program gets the info from the parent/child and displays on
screen
#include <iostream>
#include "EmployeePay.h"
using namespace std;

int main()
{
char userName[21], userSSN[13], userNum[6], userHire[10];
float userAnPay, userMoPay;
int userDepends;

//char name[21];
//char ssn[13];
//char empNumber[6];
//char hire[10];

//get all the info from the user
cout <<"Enter the employee's info:\n";
cout <<"Name: ";
cin.getline(userName, 21);
cout << "Social Security Number: ";
cin.getline(userSSN, 13);
cout << "Employee Number: ";
cin.getline(userNum, 6);
cout <<"Hire Date: ";
cin.getline(userHire, 10);
cout << "Annual Pay: ";
cin >> userAnPay;
cout << "Monthly Pay: ";
cin >> userMoPay;
cout << "Dependents: ";
cin >> userDepends;

//define a EmployeePay object and use the data entered by the user
EmployeePay myEmp(userName[21], userSSN[13], userNum[6], userHire[10],
userAnPay, userMoPay, userDepends);

//display the EmployeePay objects properties
cout << "Here are the Employee's details:\n";
cout << "Name: " << myEmp.getName() << endl;
cout << "SSN: " << myEmp.getSSN() << endl;
cout << "Employee Number: " << myEmp.getEmpNumber() << endl;
cout << "Hire Date: " << myEmp.getHire() << endl;
cout << "Annual Pay: " << myEmp.getAnPay() << endl;
cout << "Montly Pay: " << myEmp.getMoPay() << endl;
cout << "Dependents: " << myEmp.getDepend() << endl;

return 0;
}
thank you very much for any help!

Jan 16 '06 #1
12 10047
GRoll35 wrote:
I get 4 of those errors. in the same spot. I'll show my parent class,
child class, and my driver.

All that is suppose to happen is the user enters data and it uses
parent/child class to display it.

here is the 4 errors.

c:\C++\Ch15\Employee.h(29): error C2440: '=' : cannot convert from
'char []' to 'char [6]'
c:\C++\Ch15\Employee.h(27): error C2440: '=' : cannot convert from
'char []' to 'char [21]'
c:\C++\Ch15\Employee.h(28): error C2440: '=' : cannot convert from
'char []' to 'char [13]'
c:\C++\Ch15\Employee.h(30): error C2440: '=' : cannot convert from
'char []' to 'char [10]'

this is the part that it don't like in my parent class.

Employee(char n[21], char s[13], char e[6], char h[10]) //constructor
{
name = n;
Arrays are not assignable. Please use 'std::memcpy' or 'std::strcpy', or
'std::copy'.
[..]
}

Here is my parent class.

//specification file for the Employee class.
#ifndef EMPLOYEE_H
#define EMPLOYEE_H

class Employee
{
private:
char name[21];
[..]


V
Jan 16 '06 #2
TB
GRoll35 sade:
I get 4 of those errors. in the same spot. I'll show my parent class,
child class, and my driver.

All that is suppose to happen is the user enters data and it uses
parent/child class to display it.

here is the 4 errors.

c:\C++\Ch15\Employee.h(29): error C2440: '=' : cannot convert from
'char []' to 'char [6]'
c:\C++\Ch15\Employee.h(27): error C2440: '=' : cannot convert from
'char []' to 'char [21]'
c:\C++\Ch15\Employee.h(28): error C2440: '=' : cannot convert from
'char []' to 'char [13]'
c:\C++\Ch15\Employee.h(30): error C2440: '=' : cannot convert from
'char []' to 'char [10]'

this is the part that it don't like in my parent class.

Employee(char n[21], char s[13], char e[6], char h[10]) //constructor
{
name = n;
ssn = s;
empNumber = e;
hire = h;
}


Unless you're a speed-freak, consider using std::string instead,
that way you won't discriminate people with names longer than
21 characters ;)

O, by the way, you can't assign arrays to each other that way,
you have to copy source array to destination array.

--
TB @ SWEDEN
Jan 16 '06 #3
ok that fixed that problem. so now it looks like this..

Employee(char n[21], char s[13], char e[6], char h[10]) //constructor
{
strcpy(name,n);
strcpy(ssn,s);
strcpy(empNumber,e);
strcpy(hire,h);
}
but now i get this error...

c:\C++\Ch15\EmployeePay.h(16): error C2664: 'Employee::Employee(char
[],char [],char [],char [])' : cannot convert parameter 1 from 'char'
to 'char []'

and it points to this part of the code..

EmployeePay(char n, char s, char e, char h, float an, float mo, int
de) : Employee(n, s, e, h)
{
anPay = an;
moPay = mo;
depend = de;
}

anyone have any ideas?

Jan 16 '06 #4
GRoll35 wrote:
ok that fixed that problem. so now it looks like this..

Employee(char n[21], char s[13], char e[6], char h[10]) //constructor
{
strcpy(name,n);
strcpy(ssn,s);
strcpy(empNumber,e);
strcpy(hire,h);
}
but now i get this error...

c:\C++\Ch15\EmployeePay.h(16): error C2664: 'Employee::Employee(char
[],char [],char [],char [])' : cannot convert parameter 1 from 'char'
to 'char []'

and it points to this part of the code..

EmployeePay(char n, char s, char e, char h, float an, float mo, int
Do you think the types of 'n', 's', 'e', etc. , should be the same or
different from the types of the corresponding arguments in 'Employee'
constructor?
de) : Employee(n, s, e, h)
{
anPay = an;
moPay = mo;
depend = de;
}

anyone have any ideas?


V
Jan 16 '06 #5
GRoll35 wrote:
ok that fixed that problem. so now it looks like this..

Employee(char n[21], char s[13], char e[6], char h[10])
//constructor {
There's no point in the dimensions in the parameters. You can't pass
arrays, they are converted to pointers to the first element. So:

Employee(char* n, char* s], char* e, char* h)

would be clearer.
strcpy(name,n);
strcpy(ssn,s);
strcpy(empNumber,e);
strcpy(hire,h);
}
but now i get this error...

c:\C++\Ch15\EmployeePay.h(16): error C2664: 'Employee::Employee(char
[],char [],char [],char [])' : cannot convert parameter 1 from 'char'
to 'char []'

and it points to this part of the code..

EmployeePay(char n, char s, char e, char h, float an, float mo, int
de) : Employee(n, s, e, h)
That's pretty obvious, isn't it? n, s, e, and h are of type char, not
char pointers, yet you send them off to the base constructor.
anyone have any ideas?


I would strongly recommend that you stop mucking around with arrays.
Your knowledge is sketchy at this point and arrays are tough nuts prone
to error. For instance, you are using strcpy() without any protection
for array overflow. As I explained above, the dimensions in the
declaration are meaningless.

I would suggest that you use standard containers like std::string at
this stage.

Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Jan 16 '06 #6

GRoll35 wrote:
ok that fixed that problem. so now it looks like this..

Employee(char n[21], char s[13], char e[6], char h[10]) //constructor
{
strcpy(name,n);
strcpy(ssn,s);
strcpy(empNumber,e);
strcpy(hire,h);
}
but now i get this error...

c:\C++\Ch15\EmployeePay.h(16): error C2664: 'Employee::Employee(char
[],char [],char [],char [])' : cannot convert parameter 1 from 'char'
to 'char []'

and it points to this part of the code..

EmployeePay(char n, char s, char e, char h, float an, float mo, int
de) : Employee(n, s, e, h)
{
anPay = an;
moPay = mo;
depend = de;
}

anyone have any ideas?


I have several ideas, actually. First, compared to many compiler
errors, the above error is remarkably clear and concise: error C2664:
'Employee::Employee(char [],char [],char [],char [])' : cannot convert
parameter 1 from 'char' to 'char []'

In other words, the first parameter is supposed to be a char[] - that
is, an array of characters - but you have passed it a char. An array
of chars is a different type than a char. So which is it?

Second, having a constructor that takes seven arguments is strong
evidence of poor design - the chances of mixing up the order of your
arguments, leading to a very difficult-to-find error, is very high.

Third, as someone else already suggested, you need to stop using
character arrays and start using std::strings, or you are going to
drive yourself nuts. C++ has excellent library facilities. Your life
will be much easier if you use them.

Best regards,

Tom

Jan 16 '06 #7
do you mean do something like this?

EmployeePay(char n[21], char s[13], char e[6], char h[10], float an,
float mo, int de) : Employee(n[21], s[13], e[6], h[10])
{
anPay = an;
moPay = mo;
depend = de;
}
i guess i'm not getting what you trying to say. i do that and i get 2
more errors. i'll show the errors then the line of code that goes with
them. did i change what you told me to change or am i still missing
something? thank you for your help!

c:\C++\Ch15\Driver.cpp(30): error C2664: 'EmployeePay::EmployeePay(char
[],char [],char [],char [],float,float,int)' : cannot convert parameter
1 from 'char' to 'char []'

EmployeePay(char n[21], char s[13], char e[6], char h[10], float an,
float mo, int de) : Employee(n[21], s[13], e[6], h[10])
{
anPay = an;
moPay = mo;
depend = de;
}

c:\C++\Ch15\EmployeePay.h(16): error C2664: 'Employee::Employee(char
[],char [],char [],char [])' : cannot convert parameter 1 from 'char'
to 'char []'

EmployeePay myEmp(userName[21], userSSN[13], userNum[6], userHire[10],
userAnPay, userMoPay, userDepends);

Jan 16 '06 #8
GRoll35 wrote:
do you mean do something like this?

EmployeePay(char n[21], char s[13], char e[6], char h[10], float an,
float mo, int de) : Employee(n[21], s[13], e[6], h[10])
Close. You've gone too far. Whatever follows the colon is the
initialiser list. It contains, essentially, function calls. When you
call a function, and want to pass an array, you're not supposed to write
the "[21]" (or whatever) after it. If you do, you'll be _dereferencing_
the pointer (indexing the array) and that's something other than what
you're trying to achieve.
{
anPay = an;
moPay = mo;
depend = de;
}
i guess i'm not getting what you trying to say. [...]


Are you going to ask us about every compiler error you're getting? I am
not opposed asking newbie questions, but come on! Make an effort to
understand what your compiler is telling you. How much hand-holding from
the Internet community do you really expect while trying to learn
a programming language? What book are you using to learn C++?

V
Jan 16 '06 #9
i understand 100% that i need to stay away from them char arrays.
but.. in my assigment this is what it asks for the user input.

Employee Name (i guess I could do string there and have them enter
first name, then last name, then concat them.

Social security number, in the format XXX-XX-XXXX where X is a digit
within the range 0-9

Employee number, in the format XXX-L, where each X is a digit within
the range 0-9, and L is a letter within the range A-M.

Hire Date (01/01/86)

What ways could I do the ssn, emp number, and hire date so its not a
char. if i need it to be formatted like that wouldnt i need it? thanks
guys for putting up with me. I am very new to this and this is all
stuff I need to learn. I appreciate everyone helping.

Jan 16 '06 #10
GRoll35 wrote:
i understand 100% that i need to stay away from them char arrays.
but.. in my assigment this is what it asks for the user input.

Employee Name (i guess I could do string there and have them enter
first name, then last name, then concat them.
Yes, and that's easy to do with std::string.
Social security number, in the format XXX-XX-XXXX where X is a digit
within the range 0-9
That would be a string again, and you need to check the validity of the
individual characters. That's easy.
Employee number, in the format XXX-L, where each X is a digit within
the range 0-9, and L is a letter within the range A-M.
Similar.
Hire Date (01/01/86)
This is trickier, I personally wouldn't want to store the date as a
string, but your requirements may determine that.
What ways could I do the ssn, emp number, and hire date so its not a
char. if i need it to be formatted like that wouldnt i need it? thanks
guys for putting up with me. I am very new to this and this is all
stuff I need to learn. I appreciate everyone helping.


I'm not sure what you are asking. Do you mean for storage or for the
user interface?

Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Jan 16 '06 #11
GRoll35 wrote:
Employee Name (i guess I could do string there and have them enter
first name, then last name, then concat them.

Social security number, in the format XXX-XX-XXXX where X is a digit
within the range 0-9
'long' and 'unsigned long' have both enough range to represent any SSN as
a number. You will need to play tricks when outputting the number if you
want to see the leading 0s and dashes in the proper places.
Employee number, in the format XXX-L, where each X is a digit within
the range 0-9, and L is a letter within the range A-M.
You could pack it in a 'short' or 'unsigned short' value. You could store
the letter as its (L-'A') value (that's a "minus" in the expression), but
performing those conversions is sometimes a difficult task for a beginner.
Hire Date (01/01/86)
You could convert it into a 'time_t' type using 'mktime' function, but
you're probably better off packing another 'unsigned long' with exact day,
month, and year. Again, packing and unpacking can be daunting, so store
strings for now (until the requirement is to verify the validity of user
input).
What ways could I do the ssn, emp number, and hire date so its not a
char.
See above.
if i need it to be formatted like that wouldnt i need it?
Sorry, I don't understand the question.
thanks
guys for putting up with me. I am very new to this and this is all
stuff I need to learn. I appreciate everyone helping.


I think you should take it slowly and go over what you're doing again,
without our help. That way more will settle in your memory.

V
Jan 16 '06 #12
> char n[21]

O'Reilly sells a book called the C++ Pocket Reference for $9.95. It
says on page 21: "When defining a function that has an array as a
parameter, all but the first dimension must be specified for the
parameter".

In short, instead of char n[21] you have to pass char n[].

Next thing, when you pass an object by value the copy constructor of
that object is called implicitly. In your case a char n[21] doesn't
have a copy constructor (ok, i'm abstracting the abstraction), so it
doesn't fit in with the function calling convention. Blah!

Also, there is deep copy vs. shallow copy which you need to keep in
mind when making copies of arrays (using copy constructors specially)
from your class.

Jan 16 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Hoffman | last post by:
When I compile it, I get a "error C2664: 'ExtractID' : cannot convert parameter 1 from 'char' to 'char '" error and I don't understand why. I am just learning C++, so keep it simple. One more note,...
7
by: Jos De Laender | last post by:
Following simple program : #include <stdio.h> char *Convert(int Arg) { static char Buffer; printf("Convert called for %d\n",Arg); sprintf(Buffer,"%d",Arg); printf("Convert about returning...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
1
by: BigGuy316 | last post by:
I am receving this error and am completely stomped as on what could be the problem with the following code. The line which the error occurs is Set rsAircraft = objConn.Execute(strSQL). It is the last...
2
by: teddybyte | last post by:
my script below is: #include "stdafx.h" int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, ...
2
by: Nick | last post by:
I'm learning C++ and ran into a compile error using Visual C++ 2005 Express on the following example program (located at http://www.cplusplus.com/doc/tutorial/templates.html): // template...
5
by: wong_powah | last post by:
#include <vector> #include <iostream> using std::cout; using std::vector; enum {DATASIZE = 20}; typedef unsigned char data_t;
9
by: i | last post by:
#include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> char ch; int n,m; void main(); char check(int,int,char); void cash(int,int,char); void debit_card(int,int,char);
2
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.