[comp.lang.c++] conversion via

rhbartels@watcgl.waterloo.edu (Richard Bartels) (05/22/90)

I am trying to produce some classes for spline curves and I am
in need of advice on methods for conversion in C++.

To give a simplified view, Bezier and BSpline both derive from Curve.
Each of the three classes contain member data that is of variable size
(Curve has an array of points -- "control vertices" so called;
 Bezier has an array of doubles -- "breakpoints"; and BSpline has an
 array of doubles -- "knots").  To convert from Bezier to BSpline,
 one replicates each breakpoint a certain number of times.
 To convert from BSpline to Bezier, one extracts each distinct
 knot as a breakpoint (i.e. gets rid of replications), and expands
 the number of control vertices by forming certain linear combinations.)

I see two ways to proceed, both of which I want to get working.

(1) Bezier is a friend of BSpline, and BSpline is a friend of Bezier.
    BSpline defines an operator Bezier, and Bezier defines an operator BSpline.
    Each operator constructs an instance of the appropriate class,
    by copying and/or transforming whatever is necessary, and returns it.
    The "cast" syntax applies to invoke the operators: bez = (Bezier)bspl;

(2) Bezier and BSpline are friends as before, but Bezier has a constructor
    Bezier(BSpline&) and BSpline has a constructor(Bezier&).  Each constructor
    must fix up the innards of itself and its parent Curve.  The
    "constructor" syntax applies for invocation: Bezier bez(bspl);

The problem with (1) is that, AT&T2.0 seems to be reluctant to
accept "operator type ()" in all but the simplest of examples I have
tried.

The problem with (2) is that the parent class Curve is hard to
initialize when the control vertices are not available until
late in the body of the constructors.

I would appreciate any tips.  Preferably in words of one sylable.

-Richard