I have a template base class that looks roughly like this
Vector.cc:
template<typename T, unsigned int D>
class Vector {
private:
T _data[D];
...
public:
Vector(Vector<T, D>&&);
...
public:
Vector<T, D>& operator=(Vector<T, D>&&);;
};
extern template class Vector<int, 2>;
extern template class Vector<int, 3>;
extern template class Vector<int, 4>;
Vector.h
// include guard
#include "Vector.h"
template<typename T, unsigned int D>
Vector<T, D>::Vector(Vector<T, D>&&) = default;
template<typename T, unsigned int D>
Vector<T, D>& Vector<T, D>::operator=(Vector<T, D>&&) = default;
template class Vector<int, 2>;
template class Vector<int, 3>;
template class Vector<int, 4>;
// include guard
When i compile this i get the errors error: array used as initializer and error: invalid array assignment and a warning note: synthesized method [...] first required here.
When I put the = default; into the declaration in the .h file i get no errors or warnings.
I've read in multiple sources that i can put the = default; into the definition but for me it doesn't work.
What am I doing wrong? Am I missing something? Or did I simply rely on the wrong sources?
int array[5]; int array2[5]; array = array2;this is not valid in C++. You are more or less getting the same error.=defaultoutside of the class. What's your reason to do it? It's more code to write and I don't see a benefit.