2015-05-21 3 views
1

У меня есть файл заголовка 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){ 
    //... 
} 
// ... 

Тогда я хотел бы Usel его в 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

На первом, вы используете слишком. многие параметры. Это не очень хорошая практика, потому что программа не может быть легко прочитана. После этого вы должны использовать 'Algo * construct1 = new Algo (...)' или 'Algo construct1 (...)'. – Jepessen

+0

Действительно ли нужно префикс имен переменных с 'the' ..? – OJFord

+1

Параметр шаблона не используется. Возможно, это оптимизировано, как ненужное, а затем «Алго» действительно не является шаблоном. – OJFord

ответ

1

Я не думаю, что это единственная проблема, но обратите внимание на то, как вы пытаетесь ее использовать.

Конструктор:

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 параметров.

2
  1. есть «int», которого не должно быть в вашем коде. удаляйте, пожалуйста.

    template <class Type> class Algo{ 
        int // here should be deleted 
    
        public: 
        ... 
    
  2. конструктор Algo имеет много Params по умолчанию, но при определении этой функции, этот стандартный PARAMS не должен быть установлен значением в Парах-списке. вы можете сделать определение конструктора следующим образом:

    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 фиксирует, он будет работает (у меня есть попробовать его на моем компьютере) ~

Смежные вопросы