我已经阅读了有关此主题的大多数相关答案,但是我的代码似乎找不到任何错误。下面是我的代码:
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; };
};
标准宏
#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:错误:“!” token 之前的预期不合格ID”
我正在尝试在OS X上编译TSP(Travelins Salesman问题)求解器(在此处找到:http://www.cs.sunysb.edu/~algorith/implement/tsp/distrib/tsp_solve),因此,如果有人想查看整个源代码,请查看上面的链接。
最佳答案
inline void not() { val = (signed_city_id_t)!val; };
not
就像C++中的关键字,是!
token 的替代拼写。您不能将其用作函数名称。