I have a class with template functions. One of them is a constexpr function. I want to compile this class as library and use specialized template functions from other clients. Example:
//in myclass.h
struct myclass{
template<typename Entity>
static constexpr const char* myfnc1();
template<typename Entity>
static std::string myfnc2();
};
//in myclass.cpp
template<> const char* myclass::myfnc1<AnotherClass>() {return "str";}
template std::string myclass::myfnc2<AnotherClass2>() {return "str2"; }
template const char* myclass::myfnc1<AnotherClass>();
template std::string myclass::myfnc2<AnotherClass2>();
When I try to use myfnc1<AnotherClass>
at another library it says it is not defined, but I can use myfnc2<AnotherClass2>
. When I check the libmyclass.so with nm
I can see that myfnc2 template created with AnotherClass2 but myfnc1 is not. I understand that is the reason, but wonder is there anyway to make the code work it is?
I am using g++ version 4.4.2.
Thanks!
Aucun commentaire:
Enregistrer un commentaire