C
Calum
Hi,
I have a base class called Number that has subclasses Integer and
Float. I want to be able to provide a virtual operator- in the base
class so that I can subtract one Integer from another and subtract one
Float from another (I'm not too bothered about subtracting an Integer
or Float from each other). Has anyone any idea on how to do this? My
code is below - the actual code that I want to add the operator- to is
a lot more complex but I thought I would keep things simple.
class Number
{
public:
virtual ~Number() {}
};
class Integer : public Number
{
public:
Integer(int value) : m_value(value) {}
private:
int m_value;
};
class Float : public Number
{
public:
Float(float value) : m_value(value) {}
private:
float m_value;
};
Thanks.
I have a base class called Number that has subclasses Integer and
Float. I want to be able to provide a virtual operator- in the base
class so that I can subtract one Integer from another and subtract one
Float from another (I'm not too bothered about subtracting an Integer
or Float from each other). Has anyone any idea on how to do this? My
code is below - the actual code that I want to add the operator- to is
a lot more complex but I thought I would keep things simple.
class Number
{
public:
virtual ~Number() {}
};
class Integer : public Number
{
public:
Integer(int value) : m_value(value) {}
private:
int m_value;
};
class Float : public Number
{
public:
Float(float value) : m_value(value) {}
private:
float m_value;
};
Thanks.