My problem is quite simple, yet I fail to understand the cause of it and no similiar posting has turned up even after extensive research so here it is:
I have the following operator overload:
template <class T, size_t size>
inline Vector<T, size> operator + (Vector<T, size> &a, Vector<T, size> &b) {
Vector<T, size> result;
for (auto i = 0; i < size; ++i) {
result[i] = a[i] + b[i];
}
return result;
}
Obiously there's only a single code path, and this path also returns a value, but compiling under Visual Studio 2013, I get an error C4716, stating that the function instantiated by the compiler 'must return a value'. I get this error for all instantiations I've tried so far. I also get this error for every other operator overload in the same header, all of which are structured similarly to the snippet above. Am I missing something obvious here?
EDIT: This is the templated vector class definition:
template <class T, size_t size>
struct Vector {
explicit Vector(T value = static_cast<T>(0)) {
for (auto i = 0; i < size; ++i) {
_data[i] = value;
}
}
explicit Vector(const Vector &other) {
for (auto i = 0; i < size; ++i) {
_data[i] = other._data[i];
}
}
explicit Vector(T values[size]) {
for (auto i = 0; i < size; ++i) {
_data[i] = values[i];
}
}
T & operator = (const Vector &other) {
for (auto i = 0; i < size; ++i) {
_data[i] = other._data[i];
}
return *this;
}
T & operator [] (size_t index) {
return _data[index];
}
T _data[size];
};
Aucun commentaire:
Enregistrer un commentaire