What is conversion constructor?

Answer Posted / swarna sekhar dhar

A constructor that can be called with a single argument is
used for conversions from the type of the argument to the
class type. Such a constructor is called a conversion
constructor. Consider the following example:
/ spec1_conversion_constructors.cpp
class Point
{
public:
Point();
Point( int );
//...
};

int main()
{
}
Sometimes a conversion is required but no conversion
constructor exists in the class. These conversions cannot be
performed by constructors. The compiler does not look for
intermediate types through which to perform the conversion.
For example, suppose a conversion exists from type Point to
type Rect and a conversion exists from type int to type
Point. The compiler does not supply a conversion from type
int to type Rect by constructing an intermediate object of
type Point.

Is This Answer Correct ?    16 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of 'using' declaration in c++?

641


Do you need a main function in c++?

565


How a pointer differs from a reference?

704


What is the difference between set and map in c++?

616


Explain what data encapsulation is in c++?

584






What is the benefit of encapsulation?

605


What is virtual table?

637


What is istream and ostream in c++?

604


What is a c++ map?

672


Which format specifier is used for printing a pointer value?

588


Is c++ the hardest programming language?

653


Explain shallow copy?

620


What is the use of :: operator in c++?

616


What jobs can you get with a c++ certification?

598


How the programmer of a class should decide whether to declare member function or a friend function?

690