Megasoft Interview Question
Software Engineer / Developersclass can have a public method for specific data type conversions.
class sample
{
double value;
public:
sample(int i ) : value(i) {}
operator double()
{
return value;
}
};
sample obj(1);
double i = obj; // assigning object to variable i of type double.
now conversion operator gets called to assign the value.
{
- Anonymous November 30, 2010