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 type of question are asked in GE code writing test based on c++ data structures and pointers?

3513


How long it will take to learn c++?

618


Can you pass an array to a function in c++?

545


Comment on local and global scope of a variable.

587


Describe public access specifiers?

587






what is oops and list its features in c++?

554


Why can templates only be implemented in the header file?

659


What is ios class in c++?

581


State the difference between pre and post increment/decrement operations.

610


Is java based off c++?

536


How do I tokenize a string in c++?

610


What is ios in c++?

648


what are the iterator and generic algorithms.

1485


Can class objects be passed as function arguments?

609


Explain the static storage classes in c++.

709