Original Post
I would like to know how to make a copy constructor inheritable, and perhaps the operator= function as well. For instance...
// IComparable interface
class IComparable
{
public:
IComparable( const IComparable& obj );
// ...
virtual void operator=( const IComparable& obj );
virtual int lessThan( const IComparable& obj ) const;
};
// a class that derives from IComparable
class Person: public IComparable
{
public:
Person( const Person& p ): height(p.height)
{}
void operator=( const Person& p )
{
this->height = p.height;
}
int lessThan( const Person& p ) const
{
if (this->height < p.height)
return 1;
else
return 0;
}
private:
int height;
};
// now to the problem, I want to copy this IComparable object
// in part of a function
void f( IComparable obj )
{
IComparable newObject(obj);
// or similarly
IComparable newObject = obj;
}
Problem is, what if I pass in a Person to the f() function? What will operator= do? What will the copy constructor do? I''m having trouble wrapping my head around this.
--{You fight like a dairy farmer!}