错误'struct'之前的预期','或'...'
expected ',' or '...' before 'struct' error
美好的一天,
我第一次遇到这种错误。
// 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( 错误:预期的","或"..."在"结构"之前 QDataStream &operator<<(QDataStream &out, const Item::Interface &interface(
2( other.h:34:17: 错误: 'struct'之前的预期主表达式返回<
other.h:34:17: 错误:在"struct'other"之前预期';".h:34:17: 错误: 'struct'
之前的预期主表达式
在代码中的某个地方,很可能在库标头中,隐藏了以下内容(或与之非常相似的内容(:
#define interface struct
这使编译器看到以下内容:
QDataStream &operator<<(QDataStream &out, const Item::Interface &struct)
{
return out << struct.id
<< struct.pos;
}
并变得非常沮丧。
重命名参数。
我找到错误的地方是变量"接口"的名称(来自小写字母(。 将其重命名为i
,例如清除代码。
QDataStream &operator<<(QDataStream &out, const Item::Interface &i /*nterface*/)
类型Interface
命名空间中声明的,因此更改其名称没有结果。
相关文章:
- 错误:"Left of getValue must have class/struct/union"
- 在c++Primer中使用Struct和Vector时出现错误C2661
- cv::resize() 失败并出现访问冲突错误(由 NULL> 处的 <struct 引起)
- 错误 C2011 'vars::strct': 'struct' 类型重定义
- 错误:使用 tesseract 引擎时 C++ 中的声明'typedef struct tagBLOB BLOB'冲突
- 错误'struct'之前的预期','或'...'
- 在模板元编程中使用"struct xxx<>::val"导致错误
- 错误 C2864:'element::next':只能在类 (STRUCT) 中初始化静态常量整数数据成员
- C :struct中的向量,push_back错误
- 错误:未使用不完整的类型'struct std::hash<>'无效
- 得到错误"left of '.toString' must have class/struct/union",即使 toString 应该有一个合适的对象
- 将C#struct传递给C 不受管理的DLL返回错误结果
- 当编译器看到 std::vector<Typo> 和 std::vector<struct 拼写错误时发出的诊断之间的差异背后的理由是什么>
- 在内部类中使用struct时编译错误
- 错误 13 错误 C2011:'ConnectionInfo':'struct'类型重定义
- C++错误:" 'class' does not name a type"和"invalid use of incomplete type ‘struct ...' "
- 获取"Use of undefined type"和"Must have class/struct/union"错误
- 使用struct插入std::map失败,出现构造函数错误
- C++错误: map.insert(make_pair(struct, vector<struct>));
- 提升精神语法错误 - "no type named ‘size’ in ‘struct boost::spirit::unused_type’"