C++ Middle front ++ And postposition ++ It's different , Specific differences , It is shown in the following code .
At the back ++ in , Add a parameter manually (int), The main purpose is to distinguish the front ++, This parameter is not used . there int It's a dumb guy .
Parameters of a function Only type No name Then this parameter is called dummy .
class A { public: A& operator++()// Front ++, The reference is returned { data +=1; return *this; }
const A operator++(int)// Postposition ++, The value is returned { A old(*this); ++(*this); // Call before ++ return
old; } // As you can see from the code , Front ++ Compared with the post ++ efficient , Do not generate temporary objects , Do not call the copy constructor int data; }; ostream&
operator<<(ostream& os,A& a) { os<<a.data<<endl; return os; } int _tmain(int
argc, _TCHAR* argv[]) { A a={1}; cout<<a;//1 A b=++a; cout<<b;//2 cout<<a;//2 A
c=a++; cout<<c;//2 cout<<a;//3 return 0; }

Technology
©2020 ioDraw All rights reserved
Some views of a student on Hongmeng system Tiktok The matrix - Code rain ( Free delivery ) Using function to realize the exchange of two numbers (C language ) Zhejiang University data structure midterm examination questions Java Summary of basic learning (162)—— How to ensure thread safety ? Implementation and challenge of metadata service in data Lake JavaScript Do a simple guess number games Understanding neural network machine translation in three minutes PTA Quick sort PHP call shell command