I want to have a class Sorings in which to realize some sorting methods by static methods with templates. I have read here that static template methods should be realized in the .h file. Here is my code:
Sortings.h
#ifndef SORTINGS_H_
#define SORTINGS_H_
template <class T>
class Sortings {
public:
static void BubbleSort(T a[], int len, bool increasing)
{
T temp;
for(int i = len-1; i >= 1; i--)
for(int j = 0; j<= i-1; j++)
if(increasing ? (a[j] > a[j+1]) : (a[j] < a[j+1])) {
temp = a[j+1];
a[j+1] = a[j];
a[j] = temp;
}
};
};
#endif /* SORTINGS_H_ */
Sortings.cpp
#include "Sortings.h"
//empty?
Practice.cpp
#include <iostream>
#include "Sortings.h"
int main() {
int a[6] = {4,5,2,11,10,16};
Sortings::BubbleSort<int>(a,6,true);
return 0;
}
but it returns the following errors: (the lines are like that because I have commented all the rest in Practice.cpp)
Description Resource Path Location Type
'template<class T> class Sortings' used without template parameters PracticeCpp.cpp /PracticeCpp/src line 41 C/C++ Problem
expected primary-expression before 'int' PracticeCpp.cpp /PracticeCpp/src line 41 C/C++ Problem
Function 'BubbleSort' could not be resolved PracticeCpp.cpp /PracticeCpp/src line 41 Semantic Error
Symbol 'BubbleSort' could not be resolved PracticeCpp.cpp /PracticeCpp/src line 41 Semantic Error
I don't understand what the problem is. Can you help me understand what is wrong : conceptually or/and syntactically?
I am running with Eclipse Neon.3 Release (4.6.3)