#include <iostream>

class A
{

char * stringa;
public:

A(int size)
{

cout << endl <<"costruttore 1" << endl;
stringa = new char [size+1];

}

A( const A & from)
{

stringa = new char [strlen(from.stringa)+1];
strcpy(stringa,from.stringa);

}

void set (char * s)
{

strcpy(stringa,s);

}

void print ()
{

cout << stringa << " -- " << strlen(stringa) << endl;

}

};

void f(A aa)
{

cout << endl << "f:" << endl;
aa.print();
aa.set("pippo");
aa.print();

}

void main ()
{

A a0(80);
a0.set("paperino");
cout << endl << "main1:" << endl;
a0.print();
f(a0);
cout << endl << "main2:" << endl;
a0.print();

/* In questo caso, al contrario del file "copyconst.cpp", viene usato il costruttore di copia. Per questo, quando chiamo la funzione "f()", non viene eseguita la copia byteXbyte dell'oggetto, quindi l'attributo del nuovo oggetto viene allocato in un'altra zona di memoria. */

}