Home > Back-end >  C rear overloaded with flow insertion operator overloading using an error at the same time
C rear overloaded with flow insertion operator overloading using an error at the same time

Time:10-27

//the code below
#include
using namespace std;
The class Per
{
Int m_A;
Public:
Per (int num) {
M_A=num;
}
//overload & lt;
Friend ostream& Operator<(ostream& Out, Per& P) {
The out & lt; <"M_A=" & lt; Return the out;
}
//rear overloaded + +
Per operator++ (int) {
Per temp=* this;
This - & gt; M_A + +;
Return temp.
}
};
Int main ()
{
Per p (10);
cout

p++;
cout

//cout & lt; return 0;
}
//why the second at the same time use & lt;

CodePudding user response:

Friend ostream& Operator<(ostream& Out, Per& P) in Per& Per instead, P++ not an lvalue

CodePudding user response:

reference 1st floor htpidk response:
friend ostream& Operator<(ostream& Out, Per& P) in Per& Per instead, P++ not lvalue

Why add a const Per& Can again? Const Per& What is the difference between and Per?

CodePudding user response:

Reference is not normal reference value, right after the c + + 11 rvalue references & amp; & Except, added a const can reference value, right, for example const int & amp; A=1 is normal,
The int & amp; A=1 is illegal

CodePudding user response:

A class to provide best constructors, copy constructors, operator=

CodePudding user response:

//overload & lt;
Friend ostream& Operator<(ostream& Out, const Per& p) {

This is the output stream of overloading the authentic pig kidneys face

CodePudding user response:

P++ overloaded
no problemSuffix + + is the definition of the return value from increased after
Here also can't return references temporary variables, temporary variables function performs memory fails after

CodePudding user response:

cout

cout Differences is that the former is a real variable, but p++ is an expression that returns the value of the temporary as
Can refer to the former, the latter is a value type cannot reference
Added on the third floor, const reference legal value type, can explain the ostream, why must be const Per& The

  • Related