Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What is a conversion constructor?

Posted on 2002-07-12
9
Medium Priority
?
354 Views
Last Modified: 2012-05-04
What is a conversion constructor?
0
Comment
Question by:sambasivam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

722 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