#include
#include
using namespace std;
class Buf
{ public:
Buf( char* s )
{ buffer = new char[ strlen( s ) + 1 ];
strcpy( buffer, s ); }
Buf& Buf::operator=( const Buf &otherbuf )
{ if( &otherbuf != this )
{ delete [] buffer;
buffer = new char[ strlen( otherbuf.buffer ) + 1 ];
strcpy( buffer, otherbuf.buffer ); }
return *this; }
void Display() { cout << buffer << endl; }
private:
char* buffer; };
int main()
{ Buf myBuf( "my buffer" );
Buf yourBuf( "your buffer" );
myBuf.Display();
myBuf = yourBuf;
myBuf.Display(); }
# posted by samuel @ 6:12 PM