#include<iostream>
using namespace std;
class Dollar
{
private:
int dlr;
public :
Dollar(int dollar = 0)
{
dlr = dollar;
}
friend Dollar operator +(const Dollar &oper1, const Dollar &oper2);
int getDollars()
{
return dlr ;
}
};
Dollar operator +(const Dollar &oper1, const Dollar &oper2)
{
return ( oper1.dlr + oper2.dlr );
}
int main()
{
Dollar d1(4);
Dollar d2(6);
cout<< (d1 + d2).getDollars();
return 0;
}
Master programming effortlessly with Simplest Codings. From core algorithms and LLMs to clean code in Java, C++, and Python—get clear, bite-sized tutorials and practical developer guides for all skill levels.
Friday, July 9, 2010
Operator Overloading
A simple example of operator overloading
Subscribe to:
Post Comments (Atom)
-
Overview of the SSL handshake Courtesy: http://www-01.ibm.com/support/knowledgecenter Steps involved in SSL handshake (Courtesy:...
-
To implement the kind of storage which stores strings as the search keys , there is a need to have special data structures which can store ...
-
A simple implementation of a packet sniffer in C on linux platform using the libpcap library. This packet sniffer currently sniffs IP , TCP ...
No comments:
Post a Comment
Please post your valuable suggestions