Hi all,

I'm new to QT and doing a sample app from Introduction to Design Patterns in C++ with Qt, 2nd Edition (10.1.2 Exercise: CardGame GUI).

I have a class Card and a classs Hand where I have overloaded the << operator, but I get the message error: invalid operands of types 'Hand*' and 'Card*' to binary 'operator<<' when I compile.

This are my classes:

card.h

Code:
#ifndef CARD_H
#define CARD_H

#include <QObject>
#include <QLabel>

class Card : public QObject
{
    Q_OBJECT
public:
    explicit Card(QString name, QObject *parent = 0);

    QString name() const {return m_name;}
    QLabel* label(QWidget *parent = 0);
    int value() const {return m_value;}
    bool isAce() const {return m_isAce;}

private:
    QString m_name;
    int m_value;
    bool m_isAce;
};

#endif // CARD_H
card.cpp

Code:
#include "card.h"

Card::Card(QString name, QObject *parent) :
    QObject(parent)
{
    QChar value;


    m_name = name;
    m_isAce = name.startsWith('a', Qt::CaseInsensitive);
    value = name[0].toLower();
    if (value.isDigit())
    {
        m_value = value.digitValue();
    } else if (value == 'a')
    {
        m_value = 1;
    } else
    {
        m_value = 10;
    }
}

QLabel* Card::label(QWidget *parent) {

    QString fileName = QString(":/images/%1.png").arg(m_name);
    QLabel* label = new QLabel(m_name, parent);
    label->setPixmap(QPixmap(fileName));
    return label;
}
hand.h

Code:
#ifndef HAND_H
#define HAND_H

#include <QObject>

class Card;

class Hand : public QObject
{
    Q_OBJECT
public:
    explicit Hand(QString name, QObject *parent = 0);
    Hand& operator<< (Card* card);
    ~Hand();

signals:
    void handChanged();
    
public slots:
    
private:
    QString m_name;
    QList<Card*> m_cards;
};

#endif // HAND_H
hand.cpp
Code:
#include "hand.h"
#include "card.h"

Hand::Hand(QString name, QObject *parent) :
    QObject(parent)
{
    m_name = name;
}


Hand& Hand::operator<< (Card* card) {
    m_cards << card;
    return *this;
}

Hand::~Hand() {
    qDeleteAll(m_cards);
    m_cards.clear();
}
and this is the code I use to test the overloaded operator:

Code:
    Hand* hand = new Hand("hand", parent);
    Card* card1 = new Card("a1", parent);

    hand << card1;
Any help would be appreciate,

Alex B.