Re: Is using template parameter as base for class legal?
* puzzlecracker:
Consider changing the interface of Closure so that it doesn't provide direct
access to implementation details (as it is it forces an int or collection of int
member on the implementation).
I don't see a reasonable way to change that, it looks perfectly fine
to me...
class Closure {
public:
virtual int& operator[](size_t i) =0;
virtual int const& operator[](size_t i) const =0;
};
Note the references.
In an interface class a reference in a result type generally says "exposes
implementation, ungood".
alf, what do you have in mind, just curious?
I don't know what the OP means by "Closure", but at the technical level e.g.
class Closure {
public:
virtual ~Closure() {}
virtual int elem( size_t i ) const = 0;
virtual void setElem( size_t i, int v ) = 0;
};
If []-notation is deemed to be very important (I don't understand why it should
be), then a little proxy helper can help with decoupling interface from
implementation. But instead of [] it might then be an idea to consider (). E.g.,
see FAQ item 13.10.
Of course, it it's all very simple and perhaps just use-once-and-throw-away
code, then it doesn't matter.
Cheers,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?