【发布时间】:2015-05-21 08:04:22
【问题描述】:
我有一个头文件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<int>* construct1 = new Algo<int>(...)或Algo<int> construct1(...)。 -
真的有必要在变量名前加上
the..吗? -
未使用模板参数。可能它被优化掉了,因为没有必要,然后
Algo真的不是模板。
标签: c++ templates compiler-errors