开发者

Expected initializer before function name

开发者 https://www.devze.com 2023-02-26 00:37 出处:网络
#include <iostream> #include <string> using namespace std; struct sotrudnik { string name; string speciality;
#include <iostream>
#include <string>

using namespace std;

struct sotrudnik {
    string name;
    string speciality;
    string razread;
    int zarplata;
}

sotrudnik create(s开发者_如何学编程tring 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.


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

Also,

*sotrudnik

needs to be

sotrudnik*


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

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

精彩评论

暂无评论...
验证码 换一张
取 消