Q:

What is the conversion constructor in c++?

0

What is the conversion constructor?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

A constructor with a single argument makes that constructor a conversion constructor and it can be used for type conversion. Let see an example code,

#include<iostream>
using namespace std;
class Demo
{
private:
    int data;
public:
    Demo(int i)
    {
        data = i;
    }
    void Display()
    {
        cout<<" data = "<<data<<endl;
    }
};
int main()
{
    Demo obj(6);
    //call display method
    obj.Display();
    // conversion constructor is called here.
    obj = 27;
    //call display method
    obj.Display();
    return 0;
}

Answer:

data = 6
data = 27

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Interview Questions For Experienced

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What is the difference between a copy constructor ... >>
<< Can you explain the order of execution in the cons...