Out-of-line definition of constructor in fully-specialized template [duplicate]

断了今生、忘了曾经 提交于 2019-12-11 06:56:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!