Solved Implementing debug for my class
-
I have written a 3D point class because all Qt classes use float and not qreal. I need double. I would like to have the coordinates written to QDebug(); however, I keep getting compile errors.
error: ‘QDebug MyPoint3D::operator<<(QDebug, const MyPoint3D&)’ must take exactly one argument QDebug operator<< (QDebug debug, const MyPoint3D &mc); ^ QDebug operator<< (QDebug debug, const MyPoint3D &mc); QDebug <<(QDebug debug, const MyPoint3D &mc) { QDebugStateSaver saver(debug); debug.nospace() << mc.x << mc.y << mc.z; return debug; }
What am I doing wrong?
-
hi
Did you add the overload inside the class ?
The error suggest that.Normally its goes
class X {
..
};QDebug operator<< (QDebug debug, const X &mc);
and then implementation in . cpp
-
-
@aha_1980 & mrjj Yes, I remember that from serialization. Now it the implementation that gives the error, namely:
error: expected unqualified-id before ‘<<’ token QDebug <<(QDebug debug, const MyPoint3D &mc) ^
What is the problem?
-
-
@aha_1980 Thanks to both of you for your help. I had that, but was distracted by the first problem.
-
@ofmrew So please mark the topic as SOLVED. Thanks!
-
Hi
Just as a final note.
If you need to write out private variables, you need
class MyPoint3D {
friend QDebug operator<< (QDebug d, const MyPoint3D &mc);
...
}