W
www.brook
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;
}
class Aublic 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;}
}
this will not work, since the interefaces are different, A v.s.
Interace_
So a solution I have is to use
class Interface_
{
public:
virtual void operator = (const Interface *other)=0;
virtual void operator +=(const Interface *other)=0;
}
class Aublic 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!
class Interface_
{
public:
virtual void operator = (const Interface &other)=0;
virtual void operator +=(const Interface &other)=0;
}
class Aublic 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;}
}
this will not work, since the interefaces are different, A v.s.
Interace_
So a solution I have is to use
class Interface_
{
public:
virtual void operator = (const Interface *other)=0;
virtual void operator +=(const Interface *other)=0;
}
class Aublic 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!