I have a class that is derived from two identical bases:
class Vector3d {...};
class Position:public Vector3d {...};
class Velocity:public Vector3d {...};
class Trajectory:public Position, public Velocity
{
Vector3d &GetPosition(void);
Vector3d &GetVelocity(void);
};
I would like to have a member functions in derived class to quickly cast to one or the other base. What I am trying is:
Vector3d &GetPosition(void) const
{
return static_cast<const Vector3d &>(*this);
}
but I received a kind message from the compiler: "Reference initialized with 'const Position', needs lvalue of type 'Vector3d'"
When I use:
const Vector3d &GetPosition(void) const
{
return static_cast<const Vector3d &>(*this);
}
things compile ok but I cannot use it in the way that I intend:
Trajectory t;
t.Position=Set(20,30,50);
because t.Position is const and hence an improper lvalue, as the compiler announces.
Any ideas on how to reference base classes from this into a non constant dereference?