lundi 28 décembre 2015

invalid initialization of non-const reference when trying to overload input operator

I'm trying to write my first program in c++. I have a class named Card:

class Card {

public:

  enum Suit { Heart, Diamond, Club, Spade };

private:

  Suit suit;

  int value;

public:

  const static int ACE_REPRESENTATION = 1;

  Card(Suit suit, int value);

  Card(Suit suit, char identier);

  void setSuit(Suit suit);

  void setValue(int value);

  bool operator ==(const Card& card) const;

  bool operator !=(const Card& card) const;

  friend istream& operator >>(istream& in, Card& card);

};

I'm trying to implement operator>> in the source file, like this :

istream& operator >>(istream& in, Card& card) {

  in >> card.suit >> card.value;

  return in;

}

I get the error :

invalid initialization of non-const reference of type 'long double&' from an rvalue of type 'long double'

What's wrong with this code? Why do I get this error ?

Aucun commentaire:

Enregistrer un commentaire