C++ &引用;无效的纯说明符";我的意思是没有纯粹的说明符?
考虑以下代码段:C++ &引用;无效的纯说明符";我的意思是没有纯粹的说明符?,c++,g++,C++,G++,考虑以下代码段: class UltraProbe { public: ConnectProbe *CP() { return probes.CP; // if type == UP_CONNECT } private: probespec mypspec; /* Filled in by the appropriate set* function */ union { IPExtraProbeData IP; ConnectProbe *CP;
class UltraProbe {
public:
ConnectProbe *CP() {
return probes.CP; // if type == UP_CONNECT
}
private:
probespec mypspec; /* Filled in by the appropriate set* function */
union {
IPExtraProbeData IP;
ConnectProbe *CP;
// ArpProbe *AP;
} probes;
};
bool do_one_select_round(UltraScanInfo *USI, struct timeval *stime) {
UltraProbe *probe = NULL;
int errno = (probe->CP()->connect_result);
}
为什么我会得到下面的错误
scan_engine_connect.cc:592:22: error: invalid pure specifier (only ‘= 0’ is allowed) before ‘probe’
int errno = (probe->CP()->connect_result);
^
errno
是一个宏,它可能被解析为一个函数,因此我们有如下内容:
int errno_func() = (probe->CP()->connect_result);
所以编译器将其解释为试图声明一个函数。Hmm,我还没有见过一个glibc实现,其中
errno
扩展为函数调用。它应该是一个左值整数表达式。有些手册页实际上将其称为变量。@LightnessRacesinOrbit我不记得它在哪里(可能在某个模糊的嵌入式平台上),但我看到它是\define
d as(*\uErrno\u pointer())
@LightnessRacesinOrbit在VC:\define errno(*\uErrno())
@AlexD:好的,但VC不使用glibc,问题被标记了;)这当然是一个切点。我只是很惊讶,在网上找不到这样定义为errno
的glibc源代码。这无疑仍是对这个问题的正确答案。