Solved Error overloading >> operator
-
Hello,
I am trying to overload the >> operator in a class, like this:
class Sample { private: quint8 tag; quint32 time; qint16 val1; qint16 val2; qint16 val3; qint16 val4; public: Sample(); friend QDataStream &operator>> (QDataStream &in, Sample &samp) { in >> samp.tag >> samp.time >> samp.val1 >> samp.val2 >> samp.val3 >> samp.val4; return in; } };
But I have a complain saying "invalid operand between Qdatastream and Qint8". I actually was doing the same in a struct instead of a class and it was working.
Any idea ?Best
-
@DSpider
How are you usingoperator>>
in your code ? Something similar to the below code ?QFile file("[File Path]"); file.open(QIODevice::ReadOnly); QDataStream in(&file); Sample sample; in >> sample;
-
Hi @KillerSmath . Exactly. I was actually doing all of these using struct, but I want to do it as Class now.
-
@DSpider
I tested your code. The serialization is working well, so i recommend you to review your code. -
I would guess you're missing to include the QDataStream header.
-
@Christian-Ehrlicher . That was exactly the issue ! Thank you so much, did not expect this from the error message.