Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 基类按模板,如何编写构造函数?_C++_Templates_Inheritance_Constructor - Fatal编程技术网

C++ 基类按模板,如何编写构造函数?

C++ 基类按模板,如何编写构造函数?,c++,templates,inheritance,constructor,C++,Templates,Inheritance,Constructor,如何为基类名称来自模板的类编写构造函数? 当我试图编译下面的代码时,我得到了这个错误 对IMU::IMU(int)的未定义引用 在函数“全局子对象”中 >>main.cpp>IMU.h>IMU.cpp>main.cpp>IMU.h>IMU.cppIMU.cpp对于模板来说很奇怪,请看它应该是“否”,模板不是这样工作的。 >>>main.cpp<<< IMU<ADXL335> obj(8); >>>IMU.h<<<

如何为基类名称来自模板的类编写构造函数? 当我试图编译下面的代码时,我得到了这个错误

对IMU::IMU(int)的未定义引用

在函数“全局子对象”中


>>main.cpp>IMU.h>IMU.cpp>main.cpp>IMU.h>IMU.cppIMU.cpp对于模板来说很奇怪,请看它应该是“否”,模板不是这样工作的。
>>>main.cpp<<<
IMU<ADXL335> obj(8);

>>>IMU.h<<<
template <class T>
class IMU : public T
{
   public:
   const int someMember=0; 
   IMU(int);
};

>>>IMU.cpp<<<
template <class T>
IMU<T>::IMU(int x) // IMU constructor
: T()         // base constructor
, someMember(x)
{

}
>>>main.cpp<<<
IMU obj(8);

>>>IMU.h<<<
class IMU : public ADXL
{
   public:
   const int someMember=0;       
   IMU(int);
};

>>>IMU.cpp<<<
IMU::IMU(int x) // IMU constructor
: ADXL()   // ADXL constructor
, someMember(x)
{

}