Menu

error: expected ';' before '(' token

2006-10-02
2012-09-26
  • Nobody/Anonymous

    Ive been messing with this for a good hour and a half and I have no idea what is wrong. For some reason the code just doesnt want to compile.

    The errors I am getting are: "expected ';' before '(' token" and "expected ';' before "private"

    This is inside of a the public: section of a class and right above the private: section. Heres the code-

    bool checkVector(Vector & vec)
    {
         if (oper == "==")
            return (vec.getString(col) == value);
         else if (oper == "!=")
            return (vec.getString(col) != value);
         else if (oper == "<")
            return (vec.getString(col) < value);
         else if (oper == "<=")
            return (vec.getString(col) <= value);
         else if (oper == ">")
            return (vec.getString(col) > value);
         else if (oper == ">=")
            return (vec.getString(col) >= value);
    
         return false;
    }
    
    private:
      int col;
      string oper;
      string value;
    

    There are a bunch of methods about checkVector and it compiles fine when I comment out the checkVector method.

    Any ideas? I'm at a complete loss.

     
    • Nobody/Anonymous

      Old:
      bool checkVector(Vector & vec)

      Delete the space before the ampersand (&) it might be the compiler seeing a bit operator rather than... whatever you call it... an address operator?

      New:
      bool checkVector(Vector& vec)

       
    • Nobody/Anonymous

      you need to provide more context, or we won't be able to help you, check out the thread titled "PLEASE READ THIS BEFORE POSTING A QUESTION" and you should find details about what you should minimally post in order to enable other people to try to help you.

      (providing the full compile log, including a minimal self-contained, piece of source code is usually a pretty good idea)

       
    • Anonymous

      Anonymous - 2006-10-02

      If you don't know what the problem is, then extracting the information that you think is important is a dangerous practice. Post it all - the whole compile log and at lesat all the code that prceedes this.

      "Expected token" messages are normally caused by the preceeding code being in error, not the line code the message relates to. It is the preceeding code that led the compiler to expect the token. This is just the point at which its expectation was not satisfied.

      Also by extracting and paraphrasing teh erro messages, you have removed important and useful diagnostic information, such as exactly what line the message is referring to.

      Clifford

       
    • Nobody/Anonymous

      Compiler Log:

      Compiler: Default compiler
      Building Makefile: "C:\Project 1\Makefile.win"
      Executing make...
      make.exe -f "C:\Project 1\Makefile.win" all
      g++.exe -c Dbms.cpp -o Dbms.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

      In file included from Dbms.cpp:4:
      Query.h:68: error: expected `;' before '(' token

      Query.h:90: error: expected `;' before "private"

      Dbms.cpp: In function `int main(int, char**)':

      Dbms.cpp:217: error: 'class Query' has no member named 'checkVector'

      make.exe: *** [Dbms.o] Error 1

      Execution terminated

      Here is Query.h in its entirity:

      class Query
      {
      public:

      Query() {}
      
      void setColumn(string c)
      {
          // col = atoi(c);
           if (c == "0")
                 col = 0;
           else if (c == "1")
                 col = 1;
           else if (c == "2")
                 col = 2;
           else if (c == "3")
                 col = 3;
           else if (c == "4")
                 col = 4;
           else if (c == "5")
                 col = 5;
           else if (c == "6")
                 col = 6;
           else if (c == "7")
                 col = 7;
           else if (c == "8")
                 col = 8;
           else if (c == "9")
                 col = 9;
      
      }
      
      void setOper(string o)
      {
           oper = o;
      }
      
      void setVal(string v)
      {
           value = v;
      }
      
      int getCol()
      {
           return col;
      }
      
      string getOper()
      {
           return oper;
      }
      
      string getVal()
      {
           return value;
      }
      
      bool checkVector(Vector & vec)
      {
           if (oper == "==")
              return (vec.getString(col) == value);
           else if (oper == "!=")
              return (vec.getString(col) != value);
           else if (oper == "<")
              return (vec.getString(col) < value);
           else if (oper == "<=")
              return (vec.getString(col) <= value);
           else if (oper == ">")
              return (vec.getString(col) > value);
           else if (oper == ">=")
              return (vec.getString(col) >= value);
      
           return false;
      }
      

      private:

      int col;
      string oper;
      string value;
      

      }

       
    • Nobody/Anonymous

      your missing the ; at the end of your class definition
      for example:

      class Query
      {
      private:
      //stuff
      public:
      //stuff
      }; //<--- that semi colon

      Slooksterpsv - Shawn B.

       
    • Nobody/Anonymous

      yeah it looks like I did forget that, thanks (i'm used to java, so i forgot it). I put the semi-colon in and I still get the same errors, though. Very strange.

       
    • Nobody/Anonymous

      The code you have posted isn't even 90 lines long, but your error refers to line 90. You have likely omitted whitespace and/or headers somewhere. You might want to clear that up.

      I tried to compensate. I figure the second error might stem from the first. For some reason it doesn't like:

      string getVal()

      Perhaps you should investigate this. Check which headers you've included in Dbms.cpp before you include Query.h.

       
    • Nobody/Anonymous

      Yeah i omitted stuff that i had commented out, sorry for the confusion. I got it to work though.

      For some reason it didnt like bool checkVector(Vector & vec) with the parameter as a Vector (which is an object i made a template for). Anyways, I switched a bunch of my code around to just an array was being passed through checkVector and it works fine now.

      Thanks to those that tried to help.

       
    • Nobody/Anonymous

      you might have wanted to try ommitting the reference parameter, as of course not all types of arguments can be passed by reference.

       

Log in to post a comment.

MongoDB Logo MongoDB