For one reason or another, I'm forced to provide both a copy constructor and an operator= for my class. I thought I didn't need operator=
if I defined a copy ctor, but QList
wants one. Putting that aside, I hate code duplication, so is there anything wrong with doing it this way?
Fixture::Fixture(const Fixture& f) {
*this = f;
}
Fixture& Fixture::operator=(const Fixture& f) {
m_shape = f.m_shape;
m_friction = f.m_friction;
m_restitution = f.m_restitution;
m_density = f.m_density;
m_isSensor = f.m_isSensor;
return *this;
}
And just out of curiosity, there's no way to switch it so that the bulk of the code is in the copy ctor and operator=
somehow utilizes it? I tried return Fixture(f);
but it didn't like that.
It appears I need to make it more clear that the copy constructor and assignment operator have been implicitly disabled by the class I am inheriting from. Why? Because it's an abstract base class that shouldn't be instantiated on its own. This class, however, is meant to stand alone.