I came across the concept of conversion function. This is the sample code which uses both getter and conversion function.
#include<iostream>
using namespace std;
class conv
{
int val;
int a,b;
public:
conv(int x, int y)
{
a = x;
b = y;
val = 1;
val = a*b;
}
int get(){ return val; };
operator int(){ return val; };
};
int main()
{
conv obj(1,2);
int x;
x = obj; // using conversion function
cout<<"Using conversion function"<<x;
cout<<"Using getters"<<obj.get();
return 0;
}
Both cout statements produce same output. I would like to know what is the special significance of conversion function over getter function as the same could be achieved by getter function?
Thanks.