W
wongjoekmeu
Hello All,
I have the following C++ code which I do not understand. I have a class
Employee and a class String. Employee is using data members of type
String.
The definition of the overloaded constructor of Employee is as follow:
-------------
Employee::Employee(char *firstname, char *lastname, char *address, long
salary):
itsFirstname(firstname),
itsLastname(lastname),
itsAddress(address),
itsSalary(salary)
{}
-------------
This constructor requires three pointers of type char as input
parameter and one long int.
So I would suppose that when an object of type Employee is being
created that in the input parameters (the first three) should be
adresses of objects of type String. But now, to my surprise in the
main() function it is written:
-------------
Employee Edie("Jane","Doe","1461 Shore Parkway", 20000);
-------------
Why is this correct ? The first three input parameters are character
strings. How is that possible that this program compiles ?? Somewhere
in the comments of the listing it says that the class String know how
to convert a character string to a String. But if for instance this is
valid and "Jane" is being converted to a String object, but then it is
still not a pointer. Can anyone explain this to me.
Thank you in advance.
Robert
I have the following C++ code which I do not understand. I have a class
Employee and a class String. Employee is using data members of type
String.
The definition of the overloaded constructor of Employee is as follow:
-------------
Employee::Employee(char *firstname, char *lastname, char *address, long
salary):
itsFirstname(firstname),
itsLastname(lastname),
itsAddress(address),
itsSalary(salary)
{}
-------------
This constructor requires three pointers of type char as input
parameter and one long int.
So I would suppose that when an object of type Employee is being
created that in the input parameters (the first three) should be
adresses of objects of type String. But now, to my surprise in the
main() function it is written:
-------------
Employee Edie("Jane","Doe","1461 Shore Parkway", 20000);
-------------
Why is this correct ? The first three input parameters are character
strings. How is that possible that this program compiles ?? Somewhere
in the comments of the listing it says that the class String know how
to convert a character string to a String. But if for instance this is
valid and "Jane" is being converted to a String object, but then it is
still not a pointer. Can anyone explain this to me.
Thank you in advance.
Robert