sky*_*ack 6 c++ templates variadic-templates c++11
当使用可变参数模板进行模板化时,我正在努力使用成员函数的特化.
以下示例专门研究整个类,它工作正常:
template<typename... Args>
class C;
template<class T, typename... Args>
class C<T, Args...> { };
template<>
class C<> { };
int main() {
C<int, double> c{};
}
Run Code Online (Sandbox Code Playgroud)
下面的内容没有,即使它背后的想法与上面的想法完全相同:
class F {
template<typename... Args>
void f();
};
template<class T, typename... Args>
void F::f<T, Args...>() { }
int main() {
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误,我不明白它是由于:
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();
^
Run Code Online (Sandbox Code Playgroud)
在专门化功能模板时是否有一些我不知道的限制?
G ++版本是:g ++(Debian 5.2.1-23)5.2.1 20151028
编辑
顺便说一句,我从实际代码中得到的实际问题是:
non-class, non-variable partial specialization ‘executeCommand<T, Args ...>’ is not allowed
Run Code Online (Sandbox Code Playgroud)
无论如何,简化的例子类似于真实的例子.我希望这些错误并非完全不相关.
| 归档时间: |
|
| 查看次数: |
4274 次 |
| 最近记录: |