Cześć Wszystkim,
chciałbym napisać coś w stylu std::sort tylko z własnymi algorytmami sortowania (ale to nie jest istotne). W tym wypadku chcę sortować tablicę. Udało mi się napisać coś takiego:
#pragma once
template <typename Type>
class Algorithm
{
private:
public:
virtual void abstract() = 0;
static void insertion_sort(Type table[], size_t size);
};
#include "Algorithm.hpp"
template <typename Type>
static void Algorithm<Type>::insertion_sort(Type table[], size_t size)
{
for (Type i = 1; i < size; ++i)
{
Type j = i;
Type temp = table[j];
while ((j > 0) && (table[j - 1] > temp))
{
table[j] = table[j - 1];
j--;
}
table[j] = temp;
}
}
#include "Algorithm.hpp"
int main()
{
int tab[5] = { 1, 4, 8, 2, 9 };
size_t size = 5;
Algorithm<int>::insertion_sort(tab, size);
}
W tym podejściu mam błąd:
Error 2 error LNK1120: 1 unresolved externals Ścieżka\Debug\InsertionSort.exe InsertionSort
Error 1 error LNK2019: unresolved external symbol "public: static void __cdecl Algorithm<int>::insertion_sort(int * const,unsigned int)" (?insertion_sort@?$Algorithm@H@@SAXQAHI@Z) referenced in function _main Ścieżka\InsertionSort\Main.obj InsertionSort
Chciałbym żeby to wyglądało jak w wypadku std::sort bez podawania typu czyli np.:
alg::sort(Tutaj moja tablica by była);
Nie bardzo wiem jak do tego się zabrać. Czy to podejście jest dobre? Może po prostu zrobić przeciążoną funkcję w
namespace
? Ale chyba nie o to mi chodzi. Patrzyłem w implementację biblioteki algorithm, ale to trochę wyższa szkoła jazdy dla mnie... Z góry dzięki za odpowiedzi!