The phenomenon and background of the problem
Post increment cannot be chain programmed
Problem related code , Do not paste screenshots
class integer{ friend ostream& operator<<(ostream &cout, integer p);public: integer& operator++() { m_num++; return *this; } integer operator++(int) // In order to distinguish the former ++ And after ++: front ++ use function ++(void) , after ++ Use functions ++(int), This is fixed syntax { integer temp = *this; m_num++; return temp; }private: int m_num = 0;};ostream& operator<<(ostream &cout, integer p){ cout << p.m_num; return cout;}void test13(){ integer p1; cout << ((p1++)++)++ << endl; cout << p1 << endl;}
Operation results and error reporting contents
Post increment still cannot be added to 3, Can only be added to 1
My solution ideas and tried methods
What I want to achieve
Realize chain programming , Keep adding
版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/12/20211207172557028w.html