#include "stdafx.h"
Class a{
Public
int test;
A (int j=0) {
Test=j;
}
Operator overloading basic Format return value + keyword +opereator+ reload symbol + () {}
Essentially, this is exactly like a function, except that the function name is changed to Opreator
is essentially a member function or a rule that waits for a member function
int operator << (int j) {
Return J;
}
A operator + (a j) {
A C;
c.test=this->test+j.test;
return C;
}
A minimum of two parameters and also a class object parameter or enum type
Friend int operator< (A a,int J);
};
int operator< (int j,a A) {
return a.test+j;
}
Overloading is generally a friend and member function two ways
int _tmain (int argc, _tchar* argv[])
{
How to call overloaded functions of course it's a clumsy way to call.
A (3), B (3);
int j=a.operator<< (1);
printf ("The value of the member function is:%d\n", j);
Let's look at a list of overloads
A c=a.operator+ (b);
printf ("In Therory c.test are 6:c.test is%d\n", c.test);
The call of the friend function can only take the parameter 1 + operator + parameter 2 to call order can not be wrong three purposes in order to three purposes
int p=1< (a);
printf ("In Theroy P was 4:p is%d\n", p);
The core idea of a relatively simple call method is to remove the. Opereator () in other words, the object + operator + parameter mode
A m=a+b;
while (1);
return 0;
}
/*
End it. (1) Operator overloading generally has only two forms, member overloading, friend function overloading
(2) The invocation of an operator overloaded function has two kinds of 1 for a member function: Calling 2 by a member function: invoking by a simple method
The friend function is a pattern call with a parameter + operator + parameter
*/
C + + operator overloading