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

模板中的C++未知类型名称,c++,C++,达瑞 Darray.cpp 我认为它非常简单,但是当我试图用 g++Darray.cpp 这给了我一个错误 未知类型名称“DynamicTypeArray” 我做错什么了吗?这个问题现在快把我逼疯了 谢谢C++模板是以这样一种方式构建的,即不能将模板类拆分为header.h和implementation.cpp文件。似乎还可以。对不起,这是ifndef,不是ifdef,很难找到它们。 #ifdef DARRAY_H #define DARRAY_H namespace myspace{

达瑞

Darray.cpp

我认为它非常简单,但是当我试图用

g++Darray.cpp

这给了我一个错误

未知类型名称“DynamicTypeArray”

我做错什么了吗?这个问题现在快把我逼疯了


谢谢

C++模板是以这样一种方式构建的,即不能将模板类拆分为header.h和implementation.cpp文件。

似乎还可以。对不起,这是ifndef,不是ifdef,很难找到它们。
#ifdef DARRAY_H
#define DARRAY_H
namespace myspace{
    template<class T>
    class DynamicTypeArray{
    public:
           DynamicTypeArray(); 
    private:
           int length;
    };
}
#endif
#include "Darray.h"
namespace myspace{
    template <class T>
    DynamicTypeArray<T>::DynamicTypeArray(){
         length = 0;
    }
}