I looked around and tried to find an answer to this. Is it possible to define the member functions of a template class in a namespace within a cpp file? I get an error when I try to do it.
Here are the two files I am trying to compile.
ArrayList.hpp
template<typename T>
class ArrayList{
ArrayList();
~ArrayList();
}
ArrayList.cpp
#include "ArrayList.hpp"
namespace{
template<typename T>
ArrayList<T>::ArrayList(){
/* function body goes here */
}
ArrayList<T>::~ArrayList(){
/* function body goes here */
}
Compiler error
error: cannot define or
redeclare 'ArrayList<T>' here because namespace '' does not enclose
namespace 'ArrayList'
ArrayList<T>::ArrayList()