c++ - 错误: some class is not a template

标签 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 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.

您有解决办法吗?

最佳答案

  1. 代码中不应该存在“int”。请删除它。

    template <class Type> class Algo{
      int // here should be deleted
    
      public:
      ...
    
  2. 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)
    {
    //...
    }
    
  3. 做了这2个修复,就可以了。(我已经在我的电脑上试过了~)

关于c++ - 错误: some class is not a template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30367936/

相关文章:

c++ - 用大括号调用构造函数

C++ - 从可变参数模板创建元组

c++ - 可以将动态值传递给模板

c++ - 为什么 C++ 不使用 Java 之类的泛型类型删除?

c++ - 如果函数是在类范围内声明的,则 constexpr 不起作用

c - 在 hpux 11.31 上编译 ruby​​ 2.2.3 时遇到问题

c++ - 将类成员函数作为参数传递

c++ - 尝试连接两种不同类型的结构以创建链表

c# - 无法解释的内存泄漏与 Marshal.StructureToPtr

c++ - C2228使用decltype时出错