#include <iostream>
#include <string>
using namespace std;
struct sotrudnik {
string name;
string speciality;
string razread;
int zarplata;
}
sotrudnik create(string n,string spec,string raz,int sal) {
sotrudnik temp;
temp.name=n;
temp.speciality=spec;
temp.razread=raz;
temp.zarplata=sal;
return temp;
}
*sotrudnik str_compare (string str1, string str2, sotrudnik sot1, sotrudnik sot2)
I try to learn C++. But when i try to compile this code with GCC-4.4.5 by using the options " g++ -Wall -c ", I get the following error:
g++ -Wall -c "lab2.cc" (in directory: /home/ion/Univer/Cpp)
lab2.cc:11: error: expected initializer before
create
lab2.cc:20: error: expected constructor, destructor, or type conversion beforestr_compare
Compilation failed.
Both errors are tied to the function declarations. (round 11 is the declaration of function create, round 20 - of the function str_compare
). Tried to google for these kinds of errors, but couldn't find examples of similar errors, as the error messages are very generic. How can I understand their meaning and how to solve them? Thank you very much for your attention.
"Expected initializer before '. ' token" just means that it found code that didn't make sense to it - the "." character isn't legal there. Where the line is declaring a variable with a "." in the name, which is illegal because "." is an operator, and you can't declare a "multipart" variabel like that in C.
There is nothing before int main as all functions are declare and defined in different files.
The member initializer list is specified after the arguments of the constructor. It begins with a colon followed by the name of each variable to initialize, separated by commas [1]. The value to assign to each data member is specified between parenthesis after the name of each data member of the list.
You are missing a semicolon at the end of your 'struct' definition.
Also,
*sotrudnik
needs to be
sotrudnik*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With