Witam.
Dlaczego przy próbie użycia statycznej funkcji szablonowej przez statyczną funkcję w tej samej klasie otrzymuję błędy przy próbie kompilacji?
Globals.h
class Globals
{
public:
static int GetDaysBetweenTwoDates(const std::string& firstDate, std::string secondDate = "");
template <class T> static std::vector<T> Split_By_Chars(const std::string &Line, const std::string& Split, int Base = 10, int Max_Size = 0, int Skip = 0, int Start_Index = 0);
};
Globals.cpp
#include "Globals.h"
int Globals::GetDaysBetweenTwoDates(const std::string& firstDate, std::string secondDate)
{
// std::string c = "T|T";
// auto values = Globals::Split_By_Chars<int>(c, std::string("-"));
}
template <> std::vector<int> Globals::Split_By_Chars(const std::string &Line, const std::string& Split, int Base, int Max_Size, int Skip, int Start_Index)
{
std::vector<int> Result;
std::string Rest;
std::vector<std::string> Splited_To_String = Split_By_Chars_To_String(Line, { Split }, Max_Size, Skip, Start_Index);
for (auto &TB_01 : Splited_To_String) Result.push_back(strtol(TB_01.c_str(), NULL, Base));
return Result;
}
template <> std::vector<double> Globals::Split_By_Chars(const std::string &Line, const std::string& Split, int Base, int Max_Size, int Skip, int Start_Index)
{
std::vector<double> Result;
std::string Rest;
std::vector<std::string> Splited_To_String = Split_By_Chars_To_String(Line, { Split }, Max_Size, Skip, Start_Index);
for (auto &TB_01 : Splited_To_String) Result.push_back(std::stod(TB_01));
return Result;
}
main.cpp
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE P, LPSTR CMD, int nShowCmd)
{
std::string c = "T|T";
auto values = Globals::Split_By_Chars<int>(c, std::string("-"));
}
Powyższy kod kompiluję się oraz działa bez żadnych problemów, jednak po odkomentowaniu zawartości funkcji Globals::GetDaysBetweenTwoDates
przy próbie kompilacji pojawiają się poniższe błędy:
Error C2910 'Globals::Split_By_Chars': cannot be explicitly specialized
Error C2908 explicit specialization; 'std::vector<int,std::allocator<int>> Globals::Split_By_Chars<int>(const std::string &,const std::string &,int,int,int,int)' has already been instantiated