-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path40.cpp
More file actions
35 lines (29 loc) · 700 Bytes
/
Copy path40.cpp
File metadata and controls
35 lines (29 loc) · 700 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
//objects Argument.
#include<iostream>
using namespace std;
class Sample
{
public:
int a;
Sample() { a=0; } // Default Constructor
Sample(int x) // Parametrized Constructor
{
a=x;
}
void add(Sample s1,Sample s2) // taking objects as argument
{
a=s1.a+s2.a; // obj3.a=obj1.a+obj2.a;
}
};
int main()
{
Sample obj1(10); // a=10
Sample obj2(20); // a=20
Sample obj3; // a=0
obj3.add(obj1,obj2);
//obj3.a=obj1.a+obj2.a; // obj3.a=10+20;
cout<<"obj1.a:: "<<obj1.a; //10
cout<<"\nobj2.a:: "<<obj2.a; // 20
cout<<"\nobj3.a:: "<<obj3.a; //30*/
return 0;
}