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 are the various access specifiers in c++?

598


What is a tuple c++?

540


How would you use qsort() function to sort an array of structures?

714


Is java a c++?

558


Is c++ vector dynamic?

572






How do you compile the source code with your compiler?

613


What do you mean by late binding?

614


What can I use instead of namespace std?

639


What is the difference between C and CPP?

624


Where is atoi defined?

579


Name the operators that cannot be overloaded in C++?

583


What are all predefined data types in c++?

554


What does extern mean in a function declaration in c++?

697


How const int *ourpointer differs from int const *ourpointer?

606


Why #include is used?

613