//#include <iostream.h> MODIFIED: Modern library headers do not have extension.
#include <iostream>
using namespace std;
class demo {
string a;
// string *p; DELETED: Not sure what was the purpose of this.
public:
demo()
{
//a=0; DELETED: std::string already have a sane initialization.
// and assigning it to 0 looks like a bad idea to me.
// (it will be taken as a char * nullptr)
//p = new int; DELETED: We removed p. Also p was a pointer to string
//*p = NULL; DELETED: we removed p (modern C++ will use nullptr)
}
demo ( const string *q ): a(*q) // MODIFIED: use initializers
{
//p= new int; DELETED: we don't have p.
//*p=q; DELETED: we don't have p.
}
demo (demo &r):a(r.a) {
//a= r.a; MOVED as initializer.
//p= new int; DELETED: we don't have a p.
//*p= *(r.p); DELETED: we don't have a p.
}
demo (const std::string &_a):a(_a) {
// NEW: to support the constructor from string
}
~demo () {
//delete p; //No need
}
void show () {
cout << a;
}
void change (const std::string &_a) { // MODIFIED: added signature.
//s3.a=s2.a; MODIFIED: properly assign input value to member
a = _a;
}
};
int main () {
demo s1;
demo s2("Hello");
demo s3(s2);
s1.show();
s2.show();
s3.show();
s2.change("Java");
s2.show();
s3.show();
}