I am trying to write a few functions to extend the STL vector class. What I have below seems to work fine for built-in types like "double," "int," what have you, but produces an error when I use abstract types like complex<double>.

Here's my code:

Code:

#include <complex>
#include <vector>
#include <iostream>
using namespace std;
template <class D>
class statistics_vector : public vector<D> {
public:
D sum( void );
D mean( void );
};
template <class D>
D statistics_vector<D>::sum( void ) {
typename vector<D>::const_iterator position;
D arithmetic_sum = 0;
for( position = this->begin(); position != this->end(); ++position )
arithmetic_sum += *position;
return arithmetic_sum;
}
template <class D>
D statistics_vector<D>::mean( void ) {
return sum() / vector<D>::size();
}
int main( void ) {
statistics_vector<complex<double> > values;
complex<double> a( 1, 1 ), b( 2, 2 ), c( 3, 3 ), mean_value;
values.push_back( a );
values.push_back( b );
values.push_back( c );
mean_value = values.mean();
return EXIT_SUCCESS;
}

And here's the error message:

Code:

statistics_vector.cc: In member function `D statistics_vector<D>::mean() [with D = std::complex<double>]':
statistics_vector.cc:39: instantiated from here
statistics_vector.cc:28: error: no match for 'operator/' in '((statistics_vector<std::complex<double> >*)this)->statistics_vector<D>::sum [with D = std::complex<double>]() / ((std::vector<std::complex<double>, std::allocator<std::complex<double> > >*)this)->std::vector<_Tp, _Alloc>::size [with _Tp = std::complex<double>, _Alloc = std::allocator<std::complex<double> >]()'