Expected Initializer Before Function Name

Expected Initializer Before Function Name
#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 before str_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.

2 Answers

You are missing a semicolon at the end of your 'struct' definition.

Also,

*sotrudnik

needs to be

sotrudnik*
2

Try adding a semi colon to the end of your structure:

 struct sotrudnik {
    string name;
    string speciality;
    string razread;
    int zarplata;
} //Semi colon here
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.