I want to enfore the implementation of the operator overloading eg
class Interface_
{
public:
virtual void operator = (const Interface &other)=0;
virtual void operator +=(const Interface &other)=0;
}
but in the sub class
class A:public Interface_
{
public:
int m_a;
virtual void operator =(const A &other) {m_a = other.m_a;}
virtual void operator+=(const A &other){m_a += other.m_a;}
}
but this will not work, since the interefaces are different, A v.s.
Interace_
So a solution I can think is to use
class Interface_
{
public:
virtual void operator = (const Interface *other)=0;
virtual void operator +=(const Interface *other)=0;
}
but in the sub class
class A:public Interface_
{
public:
int m_a;
virtual void operator =(const _Interface *other) {m_a =
((A*)(other))->m_a;}
virtual void operator+=(const _Interface *other){m_a +=
((A*)(other))->m_a;}
};
But this looks not clean, because of the pointer conversion, it is not
safe,
Is there better solution?
Thanks in advance!