我有一个头文件Algo.h
。其内容如下:
#include <iostream>
#include <fstream>
#include <math.h>
#include <float.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
//some static functions
// ...
template <class Type> class Algo{
int
public:
Algo(int size, int num, int plth, int theN, float** theAg, int theLN,
float* theIn, float theeEps = 1E-3, float theEpsilonLR = 1E-3,
int theCycle = 30, bool DebInf = false, int theT = -1, int** theX = 0,
const char* theFileName = 0, const char* theFileNameChar = 0);
~Algo();
//some methods
//...
};
//Constructor
template <class Type> Algo<Type>::Algo(int size, int num, int plth, int theN, float** theAg, int theLN,
float* theIn, float theeEps = 1E-3, float theEpsilonLR = 1E-3,
int theCycle = 30, bool DebInf = false, int theT = -1, int** theX = 0,
const char* theFileName = 0, const char* theFileNameChar = 0){
//...
}
// ...
然后我想在main.cpp
中使用它:
#include "Algo.h"
#include <float.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;
Algo<int>* construct1(const int & rt, float** & rm); //error: Algo is not a template
Algo<int>* construct2(const int & rte, float** & rm, Algo<int>* & the1, const bool & rob1); //error: Algo is not a template
//...
int main(){
//...
return 0;
}
似乎一切都应该正常工作,但我总是收到此错误:
Algo is not a template.
您有解决办法吗?
最佳答案
代码中不应该存在“int”。请删除它。
template <class Type> class Algo{ int // here should be deleted public: ...
Algo 的构造函数有很多默认参数,但是当你定义这个函数时,这些默认参数不应该在 param-list 中设置值。您可以按如下方式定义构造函数:
template <class Type> Algo<Type>::Algo(int size, int num, int plth, int theN, float** theAg, int theLN, float* theIn, float theeEps, float theEpsilonLR, int theCycle, bool DebInf, int theT, int** theX, const char* theFileName, const char* theFileNameChar) { //... }
做了这2个修复,就可以了。(我已经在我的电脑上试过了~)
关于c++ - 错误: some class is not a template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30367936/