Hello,
i am confused whether in the following code i should return reference or not!
Is the above code correct??if Yes then B is call by value and when we return B the address of B will be changed even though we return the same object B .Right or not?Code:#include <iostream.h>
class set
{
int data;
public:
void getdata(int d)
{
data=d;
}
void putdata()
{
cout<<data;
}
set max(set B);
};
set set:: max (set B)
{
if(data>B.data)
return *this;
else
return B;
}
int main(void)
{
set a,b;
a.getdata(30);
b.getdata(20);
b=a.max(b);
b.putdata();
return 0;
}
Please tell me whether i should return reference or the above code is correct?