| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
Hi all
I know this is not a Qt issue, but I'm in doubt on how to overload the
equal operator for a QPainterPath-derived class.
My class just add an index to the QPainterPath... but how can I make
the contents of the base class equal ?
Here was my first attempt:
XPlanePath& XPlanePath::operator=(const XPlanePath& _path)
{
if (&_path == this) return *this;
index = _path.index;
// *((QPainterPath*)this) = *((QPainterPath*)_path); <---- ERROR
return *this;
}
thanks in advance
Andy
--
[ signature omitted ]
Andy Hirsh wrote: >// *((QPainterPath*)this) = *((QPainterPath*)_path); <---- ERROR QPainterPath::operator=(_path); -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
On Saturday 01 December 2007 09:49:21 Andy Hirsh wrote:
> Hi all
>
> I know this is not a Qt issue, but I'm in doubt on how to overload the
> equal operator for a QPainterPath-derived class.
>
> My class just add an index to the QPainterPath... but how can I make
> the contents of the base class equal ?
Just call the operator= from the parent:
E.g,
#include <iostream>
using namespace std;
struct A {
int m_a;
const A& operator=(const A& rhs) { m_a = rhs.m_a; return *this; }
};
struct B : public A {
int m_b;
const B& operator=(const B& rhs) {
A::operator=(rhs);
m_b = rhs.m_b;
return *this;
}
};
int main() {
B one;
B two;
one.m_a = 1;
one.m_b = 2;
two.m_a = 3;
two.m_b = 4;
two = one;
cout << "two.m_a=" << two.m_a << endl;
}
--
[ signature omitted ]