尝试在linux上使用gcc (gcc) 7.3.1 20180303 (Red Hat 7.3.1-5)编译以下代码时,得到以下错误信息,而它在windows上工作没有问题。
...
#include "DDImage/NoIop.h"
static const char* const CLASS = "RemoveChannels";
// -------------------- Header -------------------- \
class RemoveChannels : public NoIop
{
public:
//! Default constructor.
RemoveChannels (Node* node) : NoIop(node)
{
this->_message = "\w+";
this->operation = 1;
}
//! Virtual destructor.
virtual ~RemoveChannels () {}
void _validate(bool) override;
private:
//! Information private for the node.
ChannelSet channels;
std::regex rgx;
const char* _message;
int operation; // 0 = remove, 1 = keep
};
void RemoveChannels::_validate(bool for_real)
{
if (!this->_message) // Fast return if you don't have anything in there.
{
set_out_channels(Mask_None); // Tell Nuke we didn't touch anything.
return;
}
...
}
...
当我用gcc在linux上编译上面的代码时,我得到以下错误信息(在windows上它工作得很好!)。
编译错误:
RemoveChannels.cpp:28:1: error: expected unqualified-id before ‘{’ token
{
^
RemoveChannels.cpp:65:6: error: ‘RemoveChannels’ has not been declared
void RemoveChannels::_validate(bool for_real)
^~~~~~~~~~~~~~
/RemoveChannels.cpp: In function ‘void _validate(bool)’:
RemoveChannels.cpp:67:8: error: invalid use of ‘this’ in non-member function
if (!this->_message) // Fast return if you don't have anything in there.
^~~~
...
如果我删除这个->从实现函数和只使用_message,它编译和工作没有问题。
谁能给我解释一下为什么这种情况只发生在linux上而不是在windows上?
简单示例
// -------------------- Header --------------------\
class RemoveChannels
{
public:
int operation = 0;
};
int main ()
{
RemoveChannels r;
r.operation++;
}
当一行以反斜杠结束时,它在下一行继续。这意味着class RemoveChannels
意外地被注释掉了,一行注释泄漏到下一行。
// -------------------- Header --------------------
class RemoveChannels
{
public:
int operation = 0;
};
int main ()
{
RemoveChannels r;
r.operation++;
}