【发布时间】:2018-05-14 08:59:54
【问题描述】:
早安,
我第一次遇到这种错误。
// another.h
struct Item {
QString name = QString();
QString description = QString();
QVariant value = QVariant();
struct Interface {
uint id = 0;
uint pos = 0;
} mkio, uks;
struct Element {
float weight = 0;
struct Range {
uint from = 0;
uint to = 0;
} range;
int index = 0;
} element;
};
我想将此嵌套结构存储在流中。所以,
// another.h
QDataStream &operator<<(QDataStream &out, const Item::Interface &interface)
{
return out << interface.id
<< interface.pos;
}
// and another overload operator>> and operator<<...
// Another fields of the `Item` struct are compiling without any error.
1) 错误:在 'struct' 之前应有 ',' 或 '...' QDataStream &operator
2) another.h:34:17: error: 'struct' 之前的预期主表达式
返回
^
另一个.h:34:17:错误:预期的';'在“结构”之前
another.h:34:17: error: 'struct' 之前的预期主表达式
【问题讨论】:
-
您能提供一个SSCCE 吗?看来您的申报顺序有些问题。或者您忘记包含 QDataStream 标头。顺便说一句,你的代码不可读,尽量避免这种嵌套的结构声明。
-
你能在发生错误时标记行吗
-
};- 最后一行 - 它是什么? -
致 Dmitry:首先定义结构然后重载运算符。我包括 QDataStream。重新排序结构并定义
Interface没有结果...