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_Compiler Errors - Fatal编程技术网

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个参数

  • 代码中不应该有“int”。请删除它

    template <class Type> class Algo{
      int // here should be deleted
    
      public:
      ...
    
    模板类算法{
    int//此处应删除
    公众:
    ...
    
  • 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)
    {
    //...
    }
    
    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)
    {
    //...
    }