Find the answer to your Linux question:
Results 1 to 3 of 3
i get movie.cpp:5: error: expected unqualified-id before ‘using’ test.cpp:5: error: expected unqualified-id before ‘using’ error when i try to compile following code, why it can happen? here is the code: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie DeoXMAN's Avatar
    Join Date
    Jul 2005
    Location
    Azerbaijan, Germany
    Posts
    154

    error in simple C++ program


    i get
    movie.cpp:5: error: expected unqualified-id before ‘using’
    test.cpp:5: error: expected unqualified-id before ‘using’
    error when i try to compile following code, why it can happen?

    here is the code:
    <b>movie.h</b>

    #include <string>

    using namespace std;

    class movie{
    private:
    std::string name;
    int year;
    std::string director;
    std::string genre1;
    std::string genre2;
    std::string genre3;
    public:
    void print();
    void movie::setname(std::string newname);
    void movie::setyear(int newyear);
    void movie::setdirector(std::string newdirector);
    void movie::setgenre1(std::string newgenre1);
    void movie::setgenre2(std::string newgenre2);
    void movie::setgenre3(std::string newgenre3);
    std::string movie::getname();
    int movie::getyear();
    std::string movie::getdirector();
    std::string movie::getgenre1();
    std::string movie::getgenre2();
    std::string movie::getgenre3();


    }


    <b>movie.cpp</b>

    #include <iostream>
    #include <string>
    #include "movie.h"

    using namespace std;

    /*set functions*/
    void movie::setname(string newname){
    name = newname;
    }
    void movie::setyear(int newyear){
    year = newyear;
    }
    void movie::setdirector(string newdirector){
    director = newdirector;
    }
    void movie::setgenre1(string newgenre1){
    genre1 = newgenre1;
    }
    void movie::setgenre2(string newgenre2){
    genre2 = newgenre2;
    }
    void movie::setgenre3(string newgenre3){
    genre3 = newgenre3;
    }

    /*get functions*/
    string movie::getname(){
    return name;
    }
    int movie::getyear(){
    return year;
    }
    string movie::getdirector(){
    return director;
    }
    string movie::getgenre1(){
    return genre1;
    }
    string movie::getgenre2(){
    return genre2;
    }
    string movie::getgenre3(){
    return genre3;
    }

    void movie:rint(){
    cout << name << " " << year << " " << genre1 << " " << genre2 << " " << genre3 << endl;
    }


    <b>test.cpp</b>

    #include <iostream>
    #include <cstdlib>
    #include "movie.h"

    using namespace std;

    /*void seegen(movie* ; string sgenre) {

    }*/

    int main(){

    int num,i;
    movie list[100];

    do {
    cout << "How many movies?(maximum 100)" <<endl;
    cin >> num ;
    cin.get();
    } while (num>100);

    std::string name;
    int year;
    std::string director;
    std::string genre1;
    std::string genre2;
    std::string genre3;


    for (i=0;i<num;i++){
    cout << "\n Movie #" << i << endl;
    cout << "Type name of movie:"<<endl;
    cin >> name;
    list[i].setname(name);
    cout << "Type year of movie:" << endl;
    cin >> year ;
    list[i].setyear(year);
    cout << "Type director of movie:"<< endl;
    cin >> director;
    list[i].setdirector(director);
    cout << "Type genre of movie (press Enter if there is no):" << endl;
    cin >> genre1;
    list[i].setgenre1(genre1);
    cout << "Type genre of movie (press Enter if there is no):" << endl;
    cin >> genre2;
    list[i].setgenre2(genre2);
    cout << "Type genre of movie (press Enter if there is no):" << endl;
    cin >> genre3;
    list[i].setgenre3(genre3);
    }

    int b;
    string sgenre;
    cout << "Which genre are you searching for?" << endl;
    cin >> sgenre;
    for (b=0;b<num;b++){
    if((list[b].getgenre1() == sgenre) ||
    (list[b].getgenre2() == sgenre) ||
    (list[b].getgenre3() == sgenre)
    ){
    list[b].print();
    }
    }




    }

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    It is because you have not properly terminated the class definition in movie.h. It's supposed to be "class { ... };" not just "class { ... }". Without the semicolor, the compiler symbols to be declared to follow (the symbol identifier is the "unqualified-id" it expects).

  3. #3
    Linux Newbie DeoXMAN's Avatar
    Join Date
    Jul 2005
    Location
    Azerbaijan, Germany
    Posts
    154
    thank you very much!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •