【发布时间】:2022-01-01 09:58:48
【问题描述】:
假设我有一个我想用两个“重载”声明的类,一个接受 1 个模板参数,另一个接受 2 个,如下面的伪代码:
template <typename I>
class B {
public:
};
template <typename F, typename I>
class B {
};
这样B 只能用 1 或 2 个参数实例化:
B<int> hello;
B<int, int> hello2;
这样做的正确方法是什么?
【问题讨论】:
-
template <typename A, typename B = void>(或其他占位符而不是void),然后部分专门用于B == void。
标签: c++ templates overloading