C++ 错误:某些类不是模板
我有一个头文件C++ 错误:某些类不是模板,c++,templates,compiler-errors,C++,Templates,Compiler Errors,我有一个头文件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 Ty
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){
//...
}
// ...
看起来一切都应该很好,但我总是犯这样的错误:
Algo不是一个模板
你有什么办法解决它吗?我不认为这是唯一的问题,但请注意你如何尝试使用它 建造商:
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);
有许多参数。前7个是必需的,其余的是默认值,是可选的。但是,当您尝试实例化实例时:
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
Algo*construct1(常量int&rt、浮点**&rm)//错误:Algo不是模板
Algo*构造2(常量int和rte、浮点**和rm、Algo*和1、常量bool和rob1)//错误:Algo不是模板
您正在传递2个或4个参数。没有匹配的重载。
您至少需要提供前7个参数
template <class Type> class Algo{
int // here should be deleted
public:
...
模板类算法{
int//此处应删除
公众:
...
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)
{
//...
}
template Algo::Algo(int size,int num,int plth,int theN,float**theAg,int theLN,float*in,float theeEps,float theEpsilonLR,int theCycle,bool DebInf,int theT,int**theX,const char*theFileName,const char*theFileNameChar)
{
//...
}
首先,您使用的参数太多。这不是一个好的做法,因为程序不容易读取。在此之后,您应该使用
Algo*construct1=newalgo(…)
或Algo construct1(…)
。是否确实有必要在变量名称前面加上前缀。
?未使用模板参数。可能由于不必要而对其进行了优化,然后Algo
实际上不是模板。
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)
{
//...
}