I have a little problem with the specialization of the template. I was looking for other answers and thought I had found a solution in this thread - Specializing a partial template outside the class definition - however, it turns out that this does not solve my problem.
I am trying to do some specialized specialization based on enum values ββto remove the need for unnecessary polymorphism at runtime. When I define the functions of the template inside the class body, it works fine, but when I move the definitions outside the class template, the compiler cannot match the signature.
My actual script interacts with an API that uses named objects for which each class of objects that I represent has an enumeration value. Objects are not directly related to each other, but they have very similar resource management / manipulation mechanisms. At first I tried to use the traits, but due to the fact that sometimes I need to use completely different function signatures, the traits did not work as I hoped.
In any case, here is an example that I came across.
The dog works because it is defined in the class definition, but Cat meow does not, because she cannot find the meow ad. If I combine the definition and the declaration cat meow will work.
Is there a way to partially specify patterns this way? The reason is because I would like the dependency on the external API to be stored in the source file and not in the header file.
enum class AnimalType { Dog, Cat, }; template<AnimalType Type> struct A; template<> struct A<AnimalType::Dog> {
GCC 4.9 complains
scratchpad/animal.h:105: error: template-id 'meow<>' for 'void <(AnimalType)1>::meow()' does not match any template declaration void A<AnimalType::Cat>::meow()
thanks
source share