-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass10.cpp
More file actions
41 lines (39 loc) · 726 Bytes
/
Copy pathclass10.cpp
File metadata and controls
41 lines (39 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//operator overloading in cpp
// - operator overloading as binary operator
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class complex
{
private:
int a,b;
public:
void setData(int x,int y)
{
a = x; b= y;
}
void showData()
{
cout<<"a = "<<a<<" b = "<<b<<endl;
}
complex operator-()
{
complex t ;
t.a = - a;
t.b = - b;
return t;
}
};
int main(int argc, char const *argv[])
{
system("cls");
complex c1,c2;
c1.setData(3,8);
// c2 = c1.operator-();
//calling another ways
c2 = - c1; //after overloading - operator
c2.showData();
system("pause");
return 0;
}