问题
I am really ashamed to ask this question, but it looks like I don't know anything about templates after all.
So I have this snippet:
template <typename> class foo;
class bar;
template <> class foo <bar>
{
public:
foo();
};
template <> foo <bar> :: foo()
{
}
Where, well, I just have a template class foo, a class bar, a specialization foo <bar> with a constructor, and I would like to define that constructor out of line.
As trivial as this example might look like, I can't get it to compile, and I always get No function template matches function template specialization 'foo'.
If I add a dummy parameter so that the template is not fully specialized (e.g. template <bool dummy> foo <bar, dummy> :: foo()) it works nicely. What am I missing?
回答1:
The members of a full class template specialization can be defined using the ordinary member definition syntax. This is not definition for template, so template<> prefix cannot be specified.
Just change it to
foo <bar> :: foo()
{
}
来源:https://stackoverflow.com/questions/45905021/out-of-line-definition-of-constructor-in-fully-specialized-template