#include <iostream>
usingnamespace std;
class add
{
int num1, num2, sum;
public:
add()
{
cout<<" constructor without parameters ";
num1 = '\0';
num2='\0';
sum='\0';
}
add(int s1, int s2)
{
cout<<"\n constructor with parameters";
num1= s1;
num2= s2;
sum= '\0';
}
add(add &a)
{
cout<<"\ncopy const";
num1= a.num1;
num2 = a.num2;
sum= '\0';
}
void getdata()
{
cout<<"\nenter data";
cin>>num1>>num2;
}
void addition(add b)
{
sum = num1+num2+ b.num1 + b.num2 ;
}
add addition()
{
add a(5,6);
sum = num1+ num2 + a.num1 + a.num2;
}
void putdata()
{
cout<<"\nthe numbers are";
cout<<num1<<'\t'<< num2 ;
cout<< "\nthe sum of the numbers are"<<sum;
}
};
int main()
{
add a,b(10,20), c(b);
a.getdata();
a.addition();
b=c.addition();
c.addition();
cout<<"\nobj a";
a.putdata();
cout<<"\n obj b ";
b.putdata();
cout<<"\n obj c ";
c.putdata();
}
p.s the output of this program is absurd but its main motive is to understand where the copy constructor has been invoked.
also can you explain what is being done in this function block