top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

What is conversion constructor? and what is Conversion Operator?

+1 vote
100 views
What is conversion constructor? and what is Conversion Operator?
posted Dec 6, 2014 by Alwaz

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Conversion Constructor:

Constructor with a single argument makes that constructor as conversion ctor and it can be used for type conversion.

For example:
class Boo
{
public: Boo( int i );
};
Boo BooObject = 10 ; // assigning int 10 Boo object

Conversion operator:

Class can have a public method for specific data type conversions.

For example:

class Boo
{
double value;
public:
Boo(int i )
operator double()
{
return value;
}
};
Boo BooObject;
double i = BooObject;
// assigning object to variable i of type double.
now conversion operator gets called to assign the value.

answer Dec 10, 2014 by Mohammed Hussain
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...