0
class MyInt {
   int _x;
public:
   explicit MyInt(int x = 0) :_x(x) {}

   MyInt operator++(int) {
       MyInt tmp(*this);
       ++_x;
       return tmp;
   }
};

int main()
{

   MyInt a(3);
   MyInt b = ((a++) = MyInt(50));
   return 0;
}

Why is an rvalue (returned by a++) being assigned to? Is there any way to make it not compile other than changing return type of operator++ to const MyInt?

Rengar
  • 11
  • 1

0 Answers0