#include <cstring>
struct Rectangle {
int width; // member variable
int height; // member variable
char* ptr_name;
Rectangle()
:
width( 1 ),
height( 1 ),
ptr_name( nullptr )
{
set_name( "UNKNOWN" );
}
Rectangle( char const* ptr_name_, int width_ )
:
width( width_ ),
height( width_ ),
ptr_name( nullptr )
{
set_name( ptr_name_ );
}
Rectangle( char const* ptr_name_, int width_ , int height_ )
:
width( width_ ),
height( height_ ),
ptr_name( nullptr )
{
set_name( ptr_name_ );
}
~Rectangle()
{
if ( ptr_name ) delete[] ptr_name;
ptr_name = nullptr;
}
void set_name( char const* ptr_name_ )
{
if ( ptr_name ) delete[] ptr_name;
int name_length = strlen( ptr_name_ ) + 1;
ptr_name = new char[ name_length ];
strncpy( ptr_name, ptr_name_, name_length );
}
//...
};//struct Rectangle