我正在尝试添加对添加 std::vector 的支持。这是我到目前为止的代码。不起作用的部分是我尝试打印结果的部分。我知道 valarray 但我无法让它以我想要的方式工作(大多数情况下我还没有找到将向量转换为 valarray 的简单方法)。
这是错误:
../src/VectorOperations.cpp:26:6: error: need 'typename' before 'std::vector<T>::iterator' because 'std::vector<T>' is a dependent scope
class VectorOperations
{
public:
//Vector Operations
std::vector<double> logv(std::vector<double> first);
std::vector<double> raiseTo(std::vector<double> first, int power);
std::vector<double> xthRoot(std::vector<double> first, int xth);
double sumv(std::vector<int> first);
std::vector<double> operator + ( const std::vector<double> & ) const;
std::vector<double> operator - ( const std::vector<double> & ) const;
std::vector<double> operator * ( const std::vector<double> & ) const;
std::vector<double> operator / ( const std::vector<double> & ) const;
};
template <typename T>
std::vector<T> operator+(const std::vector<T>& a, const std::vector<T>& b)
{
assert(a.size() == b.size());
std::vector<T> result;
result.reserve(a.size());
std::transform(a.begin(), a.end(), b.begin(),
std::back_inserter(result), std::plus<T>());
std::cout<<"Results from addition follow: \n";
//HERE'S THE PROBLEM: I WANT TO PRINT OUT BUT I GET ERRORS
for(std::vector<T>::iterator it = a.begin(); it != a.end(); ++it) {
/* std::cout << *it; ... */
}
return result;
}