Linux g++ 编译错误:错误:预期的"",""或"..."在"||"标记之前
Linux g++ compile error: error: expected ',' or '...' before '||' token
让我首先说一下,这在Visual Studio中编译和运行良好。但当我在Linux(g++)上编译同一个文件时,由于<<
运算符重载的声明和实现,我会遇到编译错误。
代码的相关部分摘录如下。(这是一个.cpp文件,里面有Google测试用例,并且有一些类和方法定义来支持测试用例。)我省略了代码的所有相关部分(我希望如此)。
class orderrequest : public msg_adapter {
public:
// ... snip
friend bool operator ==(const orderrequest &or1, const orderrequest &or2);
friend ostream& operator <<(ostream &out, const orderrequest &or); // compiler error here
};
bool operator ==(const orderrequest &or1, const orderrequest &or2) {
bool result = or1.symbol == or2.symbol
&& or1.orderQty == or2.orderQty;
// ... snip
return result;
}
// compiler error here
ostream& operator <<(ostream &out, const orderrequest &or) {
out << "symbol=" << or.symbol << ",orderQty=" << or.orderQty;
return out;
}
编译抛出了一些错误,所有这些似乎都与试图重载<<
运算符有关:
EZXMsgTest.cpp:400: error: expected ',' or '...' before '||' token
EZXMsgTest.cpp:428: error: expected ',' or '...' before '||' token
EZXMsgTest.cpp: In function 'std::ostream& operator<<(std::ostream&, const orderrequest&)':
EZXMsgTest.cpp:430: error: expected primary-expression before '||' token
EZXMsgTest.cpp:430: error: expected primary-expression before '.' token
EZXMsgTest.cpp:430: error: expected primary-expression before '||' token
EZXMsgTest.cpp:430: error: expected primary-expression before '.' token
行400是friend ostream& operator <<
行,行430是<<
运算符的方法实现。
此外,我不确定编译器错误引用"||"标记的原因。(我被推到服务器上,按照一些说明将区域设置为"C",这在一定程度上提高了输出,但看起来仍然不太好。)
谢谢大家。
or
在C++中被保留(§2.12/2 C++11)。它是||
(§2.6/2)的替代令牌,因此不能将其用作标识符。将变量从or
重命名为其他变量以解决此问题。
参见。这篇现有的帖子了解关于替代代币的更多细节。
相关文章:
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- 这些是什么样的错误?即使我不在 Linux 上工作,我也遇到了 Linux 错误
- Arch Linux.AUR 包 mysql 不能用 makepkg 构建.错误:构建 () 中出现故障
- 分段 Linux Ubuntu 中的 g++ 错误,但在 Windows 中的 g++/MingW 中,在 C++ 中打
- [longjmp/setjmp]c++ 相同的代码窗口有异常 Linux 没有错误并且运行良好
- 在 Linux 中使用 -fvisibility=hidden 编译时出现库加载错误
- g++ 9.2.1 (Linux) 会导致 seg 错误,但 Windows 上的代码块不会
- 调试模板时出现问题.专门针对 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 错误构建失败:模板参数 1
- LINUX 操作系统上的错误:令牌之前预期的构造函数、析构函数或类型转换'('?
- 从 Linux OMI (omicli) 到 Windows WMI 的连接失败,并出现与 DMTF 相关的错误
- C++ Linux 运行时basic_string::_M_construct null 无效错误
- Stringstream编译错误仅发生在linux环境中
- 如何在长g++错误消息上使用linux less命令
- curl_easy_在Linux上执行分段错误
- 在linux上使用g++输出错误,在windows上更正
- C++新手,得到编译错误(Linux,G ++编译器)
- Android NDK示例构建错误linux
- 共享内存的std::string给分割错误(linux)
- c++ Sockets -客户端给出分段错误(linux)
- C++提升日志记录编译错误 (Linux)