Expected initializer before function name

120,946

Solution 1

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

Also,

*sotrudnik

needs to be

sotrudnik*

Solution 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
Share:
120,946

Related videos on Youtube

Ion
Author by

Ion

IT Consultant, Cyssea International, Moldova. Small experience with Python, C, C++, PHP

Updated on July 09, 2022

Comments

  • Ion
    Ion almost 2 years
    #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.

  • Ion
    Ion about 13 years
    Thank you very much, I missed that.. anyway, the second error remains the same. Is it because is returns pointer to the structure type I created?
  • Maxim Galushka
    Maxim Galushka over 8 years
    looks like this type of error happens when semicolons are missing, such mysterious c++.
  • qxz
    qxz over 7 years
    Perhaps it would be better to suggest an edit to the original answer.

Related