我在处理使用可变参数模板作为模板的成员函数的特化时遇到了困难。
以下示例对整个类进行了特化,它可以正常工作:
以下内容虽然与上面的内容完全相同,但实际上并没有起到相同的作用:
无论如何,简化的例子与实际情况类似。我希望错误不完全无关。
以下示例对整个类进行了特化,它可以正常工作:
template<typename... Args>
class C;
template<class T, typename... Args>
class C<T, Args...> { };
template<>
class C<> { };
int main() {
C<int, double> c{};
}
以下内容虽然与上面的内容完全相同,但实际上并没有起到相同的作用:
class F {
template<typename... Args>
void f();
};
template<class T, typename... Args>
void F::f<T, Args...>() { }
int main() {
}
我遇到了以下错误,但不知道它是由什么导致的:
main.cpp:7:23: error: non-type partial specialization ‘f<T, Args ...>’ is not allowed
void F::f<T, Args...>() { }
^
main.cpp:7:6: error: prototype for ‘void F::f()’ does not match any in class ‘F’
void F::f<T, Args...>() { }
^
main.cpp:3:10: error: candidate is: template<class ... Args> void F::f()
void f();
^
当专门化函数模板时,有一些我不知道的限制吗?
G++版本是:g++ (Debian 5.2.1-23) 5.2.1 20151028
编辑
顺便说一下,我从实际代码中得到的实际问题是:
non-class, non-variable partial specialization ‘executeCommand<T, Args ...>’ is not allowed
无论如何,简化的例子与实际情况类似。我希望错误不完全无关。