получая эту ошибку:
C: \ CodeBlocks \ kool \ praks3 \ vector.h | 62 | error: передача 'const Vector <2u>' в качестве аргумента 'this' для std :: string Vector:: toString () [with short unsigned int n = 2u] 'сбрасывает квалификаторы |
с этим кодом:
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
template <unsigned short n>
class Vector {
public:
std::vector<float> coords;
Vector();
Vector(std::vector<float> crds);
float distanceFrom(Vector<n> v);
std::string toString();
template <unsigned short m>
friend std::ostream& operator <<(std::ostream& out, const Vector<m>& v);
};
template <unsigned short n>
std::string Vector<n>::toString() {
std::ostringstream oss;
oss << "(";
for(int i = 0; i < n; i++) {
oss << coords[i];
if(i != n - 1) oss << ", ";
}
oss << ")";
return oss.str();
}
template <unsigned short m>
std::ostream& operator<<(std::ostream& out, const Vector<m>& v) {
out << v.toString(); // ERROR HEEEERE
return out;
}