Re: Deriving from a STL container
shazled@gmail.com wrote:
On Oct 30, 6:24 pm, bjeremy <bjer...@sbcglobal.net> wrote:
You shouldn't need to rewrite "tons of code", a standard practice is
to use composition and make an adapter class "have a" std container,
plus whatever extra functionality you need to extend the container
for in the first place.
Oops, I may have done something dodgy recently -- although it did seem
OK at the time. Is the following dangerous?
// How a time series is represented
template <typename T>
struct TimeSeries : public vector<T>
{
double noise; // An estimate of the noise variance
double delta; // The time between samples
};
I was too lazy to wrap a vector, wanted most of the vectors
functionality and felt the following was cumbersome to use:
template <typename T>
struct TimeSeries
{
vector<T> series;
double noise;
double delta;
};
Should I have gone with the second option or is there a better way?
In both cases 'series' member (or the base class) is exposed in such
a way that it can be updated without any change to 'noise' or 'delta'.
I would think that you want to keep 'series' (and the rest) private
so any update to it goes under your control so you can update the
other values accordingly...
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask