D
Darren Grant
Hi,
Is it good style to use overload operator[] for a class which isn't
really a container?
Eg, I have a class BezierPop, which represents a population of Bezier
curves (yes, we're talking Genetic Algorithms here). Should I overload
operator[] so we can use pop[4] to refer to the 4th chromosome in the
population, even though BezierPop certainly isn't a value-like class
or a container itself.
Another example, I have a class Bezier, which represents a Bezier
curve (a type of spline - just a hoopy type of curve). I have a member
function which returns a 2D coordinate as a function of t, which is an
interval of [0,1]. Should I overload operator[] so I can do curve[0.2]
or should I make a member function, eg curve.t(0.2) ?
Thanks,
Darren Grant
Is it good style to use overload operator[] for a class which isn't
really a container?
Eg, I have a class BezierPop, which represents a population of Bezier
curves (yes, we're talking Genetic Algorithms here). Should I overload
operator[] so we can use pop[4] to refer to the 4th chromosome in the
population, even though BezierPop certainly isn't a value-like class
or a container itself.
Another example, I have a class Bezier, which represents a Bezier
curve (a type of spline - just a hoopy type of curve). I have a member
function which returns a 2D coordinate as a function of t, which is an
interval of [0,1]. Should I overload operator[] so I can do curve[0.2]
or should I make a member function, eg curve.t(0.2) ?
Thanks,
Darren Grant