For starters this constructor
abc(float l,float w)
{
number1 = new float;
number2 = new float;
number1 = &l;
number2 = &w;
}
produces memory leaks. At first a memory was allocated in these statements
number1 = new float;
number2 = new float;
and its addresses were assigned to pointers. But then at once the pointers were reassigned
number1 = &l;
number2 = &w;
So the addresses to the allocated memory were lost.
The constructor can look at least the following way
abc( float l, float w ) : number1( new float( l ) ), number2( new float( w ) )
{
}
These functions
float get_1()
{
return *number1;
}
float get_2()
{
return *number2;
}
should be declared like
float get_1() const
{
return *number1;
}
float get_2() const
{
return *number2;
}
In general it is better to define these functions like
const float & get_1() const
{
return *number1;
}
const float & get_2() const
{
return *number2;
}
float & get_1()
{
return *number1;
}
float & get_2()
{
return *number2;
}
The copy constructor can look like
abc( const abc &ob)
: number1( new float( *ob.number1 ) ), number2( new float( *ob.number2 ) )
{
}
The function display should look at least like
void display() const
{
cout << "Number 1 : " << *number1 << endl;
cout << "Number 2 : " << *number2 << endl;
}
Instead of this function you could define a friend operator <<. For example
class abc
{
//...
friend std::ostream & operator <<( std::ostream &os, const abc &ob )
{
os << "Number 1 : " << *ob.number1 << std::endl;
os << "Number 2 : " << *ob.number2 << std::endl;
return os;
}
}
Also you should define explicitly the copy assignment operator and the destructor.