0

I am new to C++, I have a very simple program but it can't be compiled.

Darray.h

#ifdef DARRAY_H
#define DARRAY_H
namespace myspace{
    template<class T>
    class DynamicTypeArray{
    public:
           DynamicTypeArray(); 
    private:
           int length;
    };
}
#endif

Darray.cpp

#include "Darray.h"
namespace myspace{
    template <class T>
    DynamicTypeArray<T>::DynamicTypeArray(){
         length = 0;
    }
}

I think it is pretty straightforward, but when I try to compile it with

g++ Darray.cpp

it gives me an error

unknown type name 'DynamicTypeArray'

Am I doing anything wrong here? The problem drives me crazy right now.

Thank you

amdixon
  • 3,814
  • 8
  • 25
  • 34
user3786609
  • 211
  • 2
  • 11

1 Answers1

0

C++ templates are built in a way that (afaik) you can't have template class split over header (.h) and implementation (.cpp) files.