Problem with operator <<
-
Hi all,
I'm defining a simple custom class and I'd like to define a << operator to have a suitable debug output.
The class is defined as:class Prenotazione : public QObject { Q_OBJECT public: int _id; int _value; QDebug operator<<( QDebug dbg, const Prenotazione &myObject){ dbg << "QQQ"; return dbg; };
The compiler says that 'error C2804: 'operator <<' (binary) has too many parameters'.
I saw many examples and they are written in this way .. in don't understand why I have this error ..
Thanks!
-
@J-Hilk thanks,
the code now is accepted but I continue to have:[DataSource] p: Prenotazione(0x8098b118)
from the code:
p = new Prenotazione(); p->_id = query.value("id").toUInt(); qDebug()<< "[DataSource] p:" << p;
-
Hi all,
I'm defining a simple custom class and I'd like to define a << operator to have a suitable debug output.
The class is defined as:class Prenotazione : public QObject { Q_OBJECT public: int _id; int _value; QDebug operator<<( QDebug dbg, const Prenotazione &myObject){ dbg << "QQQ"; return dbg; };
The compiler says that 'error C2804: 'operator <<' (binary) has too many parameters'.
I saw many examples and they are written in this way .. in don't understand why I have this error ..
Thanks!
-
@SteMMo
friend
is missing, you are trying to declare a non-member operator overload that acts on a class template for the QDebug << operatorand not an overload for the Prenotazione << operator
-
@J-Hilk thanks,
the code now is accepted but I continue to have:[DataSource] p: Prenotazione(0x8098b118)
from the code:
p = new Prenotazione(); p->_id = query.value("id").toUInt(); qDebug()<< "[DataSource] p:" << p;