GCC - "expected unqualified-id before ')' token"

c++
65,065

Solution 1

Your issue is your #define. You did #define Card, so now everywhere Card is seen as a token, it will be replaced.

Usually a #define Token with no additional token, as in #define Token Replace will use the value 1.

Remove the #define Card, it's making line 22 read: 1(); or ();, which is causing the complaint.

Solution 2

(edited for updated question)

Remove the #define statements, they're mangling the file. Were you trying to implement an include guard? That would be something like this:

#ifndef CARD_H
#define CARD_H
class Card ...
...
#endif

old answer:

It means that string is not defined in the current line. Try std::string.

Solution 3

Just my two cents, but I guess you used the pre-compiled header

#define Card
#define Hand
#define AppError

as if you wanted to tell the compiler "Hey, the classes Card, Hand and AppError are defined elsewhere" (i.e. forward-declarations).

Even if we ignore the fact macros are a pain for the exact reasons your code did not compile (as John Millikin put it, mangling your file), perhaps what you wanted to write was something like:

class Card ;
class Hand ;
class AppError ;

Which are forward-declarations of those classes.

Share:
65,065
epochwolf
Author by

epochwolf

Updated on September 10, 2022

Comments

  • epochwolf
    epochwolf 3 months

    Please bear with me, I'm just learning C++.

    I'm trying to write my header file (for class) and I'm running into an odd error.

    cards.h:21: error: expected unqualified-id before ')' token
    cards.h:22: error: expected `)' before "str"
    cards.h:23: error: expected `)' before "r"
    

    What does "expected unqualified-id before ')' token" mean? And what am I doing wrong?

    Edit: Sorry, I didn't post the entire code.

    /*
    Card header file
    [Author]
    */
    // NOTE: Lanugage Docs here http://www.cplusplus.com/doc/tutorial/
    #define Card
    #define Hand
    #define AppError
    #include <string>
    using namespace std;
    // TODO: Docs here
    class Card { // line 17
        public:
            enum Suit {Club, Diamond, Spade, Heart};
            enum Rank {Two, Three, Four, Five, Six, Seven, Eight, Nine,
                       Ten, Jack, Queen, King, Ace};
            Card(); // line 22
            Card(string str);
            Card(Rank r, Suit s);
    

    Edit: I'm just trying to compile the header file by itself using "g++ file.h".

    Edit: Closed question. My code is working now. Thanks everyone! Edit: Reopened question after reading Etiquette: Closing your posts

  • Jesse Beder
    Jesse Beder over 14 years
    And make sure that <string> is included.
  • epochwolf
    epochwolf over 14 years
    Sorry, I didn't show the entire file. The question has been edited.
  • epochwolf
    epochwolf over 14 years
    I just edited the question to show the top of the file. Sorry about that.
  • epochwolf
    epochwolf over 14 years
    Yup, that was the problem. I forgot to add the include guard.
  • epochwolf
    epochwolf over 14 years
    Thank you for the explaination. That makes sense now. I think I will do some reading in my book. The professor seems to be skipping details.