What is the conversion constructor?
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; }
data = 6data = 27
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
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,
Answer:
data = 6
need an explanation for this answer? contact us directly to get an explanation for this answerdata = 27