C++ Operator Overloading
In C++ the overloading principle applies not only to functions, but to operators too. That is, of operators can be extended to work not just with built-in types but also classes. A programmer can provide his or her own operator to a class by overloading the built-in operator to perform some specific computation when the operator is used on objects of that class.
An example of operator overloading
File /home/Alvin/git_projects/octopress/source/downloads/code/03operator_overload.cpp could not be found
In order to allow operations like cin>>f, in above code we overloaded the “>>”operator. And in order to access the private memebers in the implementations, we use keyworkd “friend”.A important trick that can be seen in this general way of overloading IO is the returning reference for istream/ostream which is needed in order to use them in a recursive manner:
1
|
|