'Member specialization does not match any template declaration

The code below compiles except for the lines

template <> std::map<std::string, std::function<Goo*(Foo*)>>& Factory::getMap<Goo, Foo*>() {
    return gooMap;
}

What is wrong here, and how would it be fixed? The compiler (GCC 11.2) states that the member specialization does not match any template declaration, but to me it looks like it does.

#include <map>
#include <functional>

struct Foo;  struct Goo;

struct Factory {
    std::map<std::string, std::function<Foo*()>> fooMap;
    std::map<std::string, std::function<Goo*(Foo*)>> gooMap;
    
    template <typename T, typename U, typename... Args>
    std::function<T*(Args&&...)> create() {
        return [](Args&&... args) -> T* { return new U(std::forward<Args>(args)...); };
    }
    
    template <typename T, typename... Args>
    std::map<std::string, std::function<T*(Args&&...)>>& getMap();
    
    template <typename T, typename U, typename... Args>
    void registerFunction (const std::string& name) {
        getMap<T, Args...>()[name] = create<T, U, Args...>();
    }
};
template <> std::map<std::string, std::function<Foo*()>>& Factory::getMap<Foo>() {
    return fooMap;
}
template <> std::map<std::string, std::function<Goo*(Foo*)>>& Factory::getMap<Goo, Foo*>() {
    return gooMap;
}

int main() {}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source