Out-of-line definition of constructor in fully-spe

2019-07-28 11:46发布

This question already has an answer here:

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条回答
做自己的国王
2楼-- · 2019-07-28 11:52

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()
{
}
查看更多
登录 后发表回答