Nullified
Nullified

Reputation: 3

C++: error: expected unqualified-id before ‘!’ token

I've read most of the relevant answers on this topic already, but I can't seem to find anything wrong with my code. Below is my code:

oneaborq.cc

...
#include "stdmacro.h"
...

class marker_t {
public:
   signed_city_id_t val;
   inline marker_t() { val = 0; };
   inline signed_city_id_t is_true() { return val; };
   inline signed_city_id_t is_false() { return (signed_city_id_t)!val; };
   inline void make_true() { val = 1; };
   inline void not() { val = (signed_city_id_t)!val; };
};

stdmacro.h

#define LARGE_CITY_ID
...
typedef
#ifdef UNSIGNED_CITY_ID
unsigned
#else
signed
#endif
#ifdef LARGE_CITY_ID
short
#else
char
#endif
city_id_t;

/* signed_city_id_t is the same sizeof() as the city_id_t but can be negative
 * and should be asserted not to go more than positive MAX_DEGREE/2
 */
typedef
signed
#ifdef LARGE_CITY_ID
short
#else
char
#endif
signed_city_id_t;

I've tried changing "signed_city_id_t" to be explicitly "short" or "int" in oneaborq.cc, but that didn't seem to help. I've also tried just changing the entire class definition to:

class marker_t {
public:
   int val;
   inline marker_t() { val = 0; };
   inline int is_true() { return 0; };
   inline int is_false() { return 0; };
   inline void make_true() { val = 1; };
   inline void not() { val = 0; };
};

Even when there is no "!" in the entire class definition, it still gets the same error: "oneaborq.cc:207: error: expected unqualified-id before ‘!’ token"

I'm trying to compile a TSP (Travelins Salesman Problem) solver (found here: http://www.cs.sunysb.edu/~algorith/implement/tsp/distrib/tsp_solve) on OS X, so if anybody wants to see the entire source code, take a look at the link above.

Upvotes: 0

Views: 1377

Answers (1)

Johannes Schaub - litb
Johannes Schaub - litb

Reputation: 507343

inline void not() { val = (signed_city_id_t)!val; };

not is like a keyword in C++ and is an alternative spelling for the ! token. You cannot use it as the name of a function.

Upvotes: 5

Related Questions