Solved

What is a conversion constructor?

Posted on 2002-07-12
9
342 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 300 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

840 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