0
Can any one find the problem ,it suppose to print return.
2 Respostas
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");
}
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.