错误:某些类不是模板

Error: some class is not a template

本文关键字:错误      更新时间:2023-10-16

我有一个头文件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不是模板

你有什么好主意吗?

  1. 有一个"int",它不应该出现在你的代码中。请删掉它。

    template <class Type> class Algo{
      int // here should be deleted
      public:
      ...
    
  2. Algo的
  3. 构造函数有许多默认参数,但是在定义该函数时,这些默认参数不应该在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)
    {
    //...
    }
    
  4. 做这两个修复,它将工作。(我在电脑上试过了~)

我不认为这是唯一的问题,但要注意如何使用它。

构造函数:

 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

传递2或4个参数。没有匹配过载。您需要提供至少前7个参数。