C
Christian Meier
Baloff said:Hello
I am not sure why my compiler will not initialize
string e1("sam");
and will initialize
string e1 = "sam";
here is my code and the error.
thanks alot
********************code********************
#include <iostream>
#include <string>
using namespace std;
typedef struct
{
string firstname;
string lastname;
int age;
}
employees;
int main(){
employees e1, e2;
e1.firstname = "sam";
e1.lastname = "Jesse";
e1.age=11;
e2.firstname ("sam2");
e2.lastname("Jesse2");
e2.age(22);
These statements do not initialize, I think. As your error messages say,
operators/functions of string/int are called with these three statements.
cout << "employee e1\n\t" << e1.firstname << "\n\t"
<< e1.lastname << "\n\t" << e1.age << endl;
cout << "employee e2\n\t" << e2.firstname << "\n\t"
<< e2.lastname << "\n\t" << e2.age << endl;
}
********************Error********************
cd /home/sam/Exercies/ThinkingInC++/Vol1/C03/15/
make -k
g++ -g -c -o main.o main.cpp
main.cpp: In function `int main()':
main.cpp:20: error: no match for call to `(std::string) (const char[5])'
main.cpp:21: error: no match for call to `(std::string) (const char[7])'
main.cpp:22: error: call to non-function `employees::age'
make: *** [main.o] Error 1
make: Target `proj1' not remade because of errors.
Compilation exited abnormally with code 2 at Thu Jul 28 16:46:34