I have some code that looks like this in an Array.hpp
file
template <typename T>
class Array {
private:
T *_array;
int _arrSize;
public:
Array<T>();
Array<T>(unsigned int n);
...
};
then on the Array.cpp
file I have like this
#include "Array.hpp"
template <typename T>
Array<T>::Array<T>(){};
template <typename T>
Array<T>::Array<T>(unsigned int n) : _arrSize(n) {
T *a = new T[n];
for (unsigned int i = 0; i < n; i++) {
a[i] = 0;
}
this->_array = a;
};
...
then a main as simple as
int main() {
Array<int> g(2);
return 0;
}
but when I try to compile this with clang++ -Wall -Wextra -Werror -std=c++98 *.c
I get this error
Array.cpp:16:11: error: out-of-line constructor for 'Array' cannot have template arguments Array<T>::Array<T>(){}; ^ ~~~ Array.cpp:19:11: error: out-of-line constructor for 'Array' cannot have template arguments Array<T>::Array<T>(unsigned int n) : _arrSize(n) { ^ ~~~
I'm not sure what I'm doing wrong