I've got an old C arithmetic library that I want to convert to C++.
There are about 30 routines, which all take pointers to an arithmetic
structure.
I'd like to convert this to C++, so that the user sees only a new
arithmetic class, with overloaded arithmetic ops (+/-/etc) which call
the old C code under the hood. The user doesn't need to see the old C
code. The new class contains only a few fields, and the user doesn't
need to see these either.
The problem is, I can see 2 or 3 ways to do this, and it's starting to
get messy. Any advice on how to do this? I'm currently using
combinations of these 3:
1 - The C functions are all private member methods, with direct access
to the new fields. This is the easiest, but may have long-term
maintenance problems. The library user also finds out about the
existence of the C routines, since they're declared in the class
header. This is not really a problem, but I'd prefer the header to be
clean.
2 - The C functions are all external, in their own namespace, and the
class declares them as friends, so they can still see the class
internals. Again, perhaps not good in the long term.
3 - The C functions are again all external, in their own namespace. I
now have access methods for all the private class fields, and the C++
and C code is modified to use these access methods. This is messy, but
I suppose it's the Right Thing to do.
?
Thanks -
Paul