A class can have a public method for specific data type conversions. It means you can define a member function of a class that converts from the type of its class to another specified type. It is called a conversion function, See the below example,
#include <iostream>
using namespace std;
class Demo
{
double value;
public:
Demo(double data )
{
value = data;
}
operator double()
{
return value;
}
};
int main()
{
Demo BooObject(3.4);
/*assigning object to variable mydata of type double.
Now conversion operator gets called to assign the value.*/
double mydata = BooObject;
cout << mydata <<endl;
}
Answer:
A class can have a public method for specific data type conversions. It means you can define a member function of a class that converts from the type of its class to another specified type. It is called a conversion function, See the below example,
Output: 3.4
need an explanation for this answer? contact us directly to get an explanation for this answer