我在类中有一个类和一个结构,如下所示:
class MyClass : public QObject
{
public:
....
struct MyStruct
{
quint8 val1;
}
};
我想为结构重载运算符 << 和 >>,但我不知道该怎么做。目前,我确实喜欢这样:
class MyClass : public QObject
{
public:
....
struct MyStruct
{
quint8 val1;
QDataStream &operator<<(QDataStream &out, const MyStruct& _myStruct)
{
out << _myStruct.val1;
return out;
}
QDataStream &operator>>(QDataStream &in, MyStruct& _myStruct)
{
in >> _myStruct.val1;
return in;
}
};
};
但这不行