I am trying to overload the += opperator on my template Vector class.
template<unsigned int dimensions, typename TValue>
class Vector
{
private:
std::array<TValue, dimensions> m_values;
public:
Vector(){
for (int i = 0; i < dimensions; i++){
m_values[i] = TValue();
}
};
Vector(std::array<TValue, dimensions> elements){
for (int i = 0; i < dimensions; i++){
m_values[i] = elements[i];
}
};
inline void set(VectorDimensions dimension, TValue value){
m_values[dimension] = value;
};
inline TValue get(VectorDimensions dimension) const{
return m_values[dimension];
};
inline unsigned int getSize() const{
return dimensions;
};
const std::array<TValue, dimensions> getValues() const{
return m_values;
};
friend ostream& operator<<(ostream& os, const Vector<dimensions, TValue>& vt) {
array<TValue, dimensions> values = vt.getValues();
os << '[';
for (unsigned int i = 0; i < vt.getSize(); i++){
os << values[i] << values[i+1] ? ", " : "";
}
os << ']';
return os;
};
friend Vector<dimensions, TValue>& operator+=(const Vector<dimensions, TValue>& vt) {
array<TValue, dimensions> values = vt.getValues();
for (unsigned int i = 0; i < vt.getSize(); i++){
m_values[i] += values[i];
}
return *this;
};
};
Upon adding the overload for the += opperator I get many of the following errors:
error C2805: binary 'operator +=' has too few parameters
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2334: unexpected token(s) preceding '{'; skipping apparent function body.
error C2238: unexpected token(s) preceding ';'
syntax error : missing ';' before '<'
error C2143: syntax error : missing ';' before '++'
error C2143: syntax error : missing ')' before ';'
error C2059: syntax error : 'return'
error C2059: syntax error : 'for'
error C2059: syntax error : ')'
An explanation as to why or how these errors actually get caused by whatever it is that I have done wrong may be useful. Thanks