Can any one find the problem ,it suppose to print return. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Can any one find the problem ,it suppose to print return.

https://code.sololearn.com/cUqNs30wK1rG/?ref=app

8th Apr 2018, 9:35 AM
Brijish
2 Réponses
0
What are you trying to do? I can only guess. #include <iostream> using namespace std; class MyClass { public: MyClass(string x); ~MyClass(); }; MyClass::MyClass(string x) { cout<< "Constructor"<<endl; } MyClass::~MyClass() { cout<<"Destructor"<<endl; } int main() { MyClass obj("fred"); }
8th Apr 2018, 9:47 AM
Emma
0
You need to place 'return x' inside the constructor's definition, after the cout statement. Also, you would have to rewrite the statement : 'cout<<MyClass("constructor")<<endl;' to : 'cout<<"Constructor"<<endl;' as the original statement leads to infinite recursion, as each constructor call creates another temporary object which never lets the original constructor finish its task.
8th Apr 2018, 9:47 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar