简体   繁体   English

如何在声明之外定义一个专用于无参数的可变参数模板类的C ++方法?

[英]how to define a C++ method outside the declaration for a variadic templated class specialized to no parameters?

I have a variadic templated class that I want to specialize to take no parameters and then I want to define methods outside the class declaration. 我有一个可变的模板类,我想专门没有参数,然后我想在类声明之外定义方法。

But the following gives 但以下给出

error: template-id ‘foobar<>’ for ‘foobar<>::foobar()’ does not 
match any template declaration

What am I doing wrong? 我究竟做错了什么?

template <typename ...> class foobar;

template <>
class foobar <> 
{
    foobar();
};

//does not work!?
template <>
foobar<>::foobar() {};

The constructor isn't a template, since it's a non-template member of a full specialisation, so it doesn't need template in its declaration: 构造函数不是模板,因为它是完全特化的非模板成员,因此它的声明中不需要template

// does work
foobar<>::foobar() {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 C++ 中的类体之外定义一个专门的类方法? - How to define a specialized class method outside of class body in C++? 如何专门化在可变参数模板 class 中定义的可变参数方法? - How to specialized a variadic argument method defined inside a variadic templated class? 如何定义嵌套在类声明之外的模板化类中的模板化类方法的特化? - How can you define a specialization of a method of a templated class nested in a templated class outside of the class declaration? 如何在类声明之外定义嵌套模板类&#39;方法? - How do you define a nested templated class' method outside of the class declaration? 模板化类声明C ++ - Templated class declaration c++ C ++ - 如何在模板化类之外实现模板化成员函数 - C++ - how to implement templated member function outside a templated class 如何在类主体之外定义类模板的模板化方法 - How to define a templated method of a class template outside of class body c++ 模板化 class 带有指向可变参数 function 的函数指针 - c++ templated class with functionpointer to variadic function 使用专门的可变参数模板类的声明 - using declaration of a specialized variadic template class 模板类,使用一种专门用于C ++的方法 - template class with a single method specialized in C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM