Posted by MindBreaker at 8:27 AM
Read our previous post
Object:
How to overload the objects and passing them to the class and add all the objects one by one.
Source code:
#include <iostream>
using namespace std;
class count
{
int counter;
public:
count()
{
counter=0;
};
count(int a)
{counter =a;};
int getcount()
{
return counter;
}
count operator+(count a)
{
return count(counter+a.counter);
}
};
void main()
{
count cnt1(10),cnt2(34),cnt3;
cnt3=cnt1+cnt2 ;
cout << cnt3.getcount();
}
Output:
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.