c ++模板中的未知类型名称

时间:2015-05-10 06:45:43

标签: c++

我是C ++的新手,我有一个非常简单的程序,但它无法编译。

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;
    }
}

我认为这很简单,但是当我尝试使用

进行编译时
  

g ++ Darray.cpp

它给了我一个错误

  

未知类型名称&#39; DynamicTypeArray&#39;

我在这里做错了吗?这个问题让我现在发疯了。

谢谢

1 个答案:

答案 0 :(得分:0)

C ++模板的构建方式是(afaik)您不能将模板类拆分为标题(.h)和实现(.cpp)文件。