C++:错误:在“!”之前应为不合格的id代币

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

本文关键字:不合格 id 代币 错误 C++      更新时间:2023-10-16

我已经阅读了关于这个主题的大多数相关答案,但我似乎没有发现我的代码有任何错误。以下是我的代码:

一个aborq.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;

我曾尝试在oneaborq.cc中将"signed_city_id_t"更改为显式的"short"或"int",但这似乎没有帮助。我还尝试将整个类的定义更改为:

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; };
};

即使在整个类定义中没有"!",它仍然会得到相同的错误:"oneaborq.cc:207:错误:在'!'标记之前应为不合格的id"

我正在尝试编译一个TSP(Travelins Salesman Problem)求解器(可在此处找到:http://www.cs.sunysb.edu/~algorith/eimplement/tsp/distrib/tsp_solution),所以如果有人想查看整个源代码,请查看上面的链接。

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

not类似于C++中的关键字,并且是!标记的替代拼写。不能将其用作函数的名称。