0

I have set a of objects

struct card {
  int rank;
  int suit;
}
typedef std::pair<card, card> hand;
hand operator=(const hand& rhs);

I want to make a new object of type hand = to an other hand. but I get

error: 'hand operator=(const hand&)' must be a nonstatic member function

how do I make this operator nonstatic?

Meechew
  • 49
  • 5
  • `operator=` must be a function inside a class, it has no meaning outside. – gkpln3 Jun 01 '20 at 08:08
  • Sounds like what you are trying to do is this: `hand hand; hand second_hand(hand);`, search for copy constructor. – gkpln3 Jun 01 '20 at 08:10
  • You cannot add `operator=` to an `std::` type, because `operator=` must be a class member and you cannot modify `std::` types. You need to find a different solution (perhaps a copy constructor as suggested in the other comment) – Yksisarvinen Jun 01 '20 at 08:14
  • 2
    I didn't originally notice you were trying to assign `hand` to `hand`. You don't need to define an operator for that. `std::pair` already defines an assignment operator. The typedef is not a new type, it's just another name for an existing type. And the existing type already does what you want. – StoryTeller - Unslander Monica Jun 01 '20 at 08:18

0 Answers0