Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What is a conversion constructor?

Posted on 2002-07-12
9
Medium Priority
?
359 Views
Last Modified: 2012-05-04
What is a conversion constructor?
0
Comment
Question by:sambasivam
9 Comments
 

Author Comment

by:sambasivam
ID: 7149312
What is a conversion constructor?
0
 
LVL 86

Accepted Solution

by:
jkr earned 1200 total points
ID: 7149339
A 'conversion ctor' will construct an object from a different data type, and that's why they are called that way. They take a single non-default argument which is not of the same type than the conversion target. Here's an example from the VC++ docs that illustrates it:

Conversion Constructors
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:

class Point
{
public:
   Point();
   Point( int );
   ...
};

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.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7154264
As you just were around regarding http://www.experts-exchange.com/cplusprog/Q_20322631.html - do you have any more questions on this one?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:jkr
ID: 7163757
is there anything that you would like to ask as a followup?
0
 
LVL 86

Expert Comment

by:jkr
ID: 7170823
Hmm, are you still with us?
0
 
LVL 86

Expert Comment

by:jkr
ID: 7178451
sambasivam? Do you need more explanation?
0
 
LVL 11

Expert Comment

by:griessh
ID: 7376035
Dear sambasivam

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "jkr"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 

Expert Comment

by:KalluMama
ID: 12765764
where can i find more information on conversion constructor
0
 
LVL 86

Expert Comment

by:jkr
ID: 12765915
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question