【发布时间】:2018-07-12 23:33:49
【问题描述】:
我正在尝试使用 C++ 可变参数模板来解压缩变量类型的参数列表,我将如何删除以下人工示例中的“T”对象:
struct Test
{
template <typename T, typename... Args>
void foo(T t, int i, Args... args) { foo(t, args...); }
template <typename T, typename... Args>
void foo(T t, double d, Args... args) { foo(t, args...); }
template <typename T>
void foo(T t) { }
};
struct DummyObject { };
然后像这样执行:
DummyObject dummy;
Test test;
test.foo(dummy, 4, 5.0, 6, 7.0, 8.0, 9);
我想完全消除传递“虚拟”对象的需要,我只是无法弄清楚在这种情况下最终的“foo”函数应该是什么样子。
【问题讨论】:
-
要回答这个问题,我们需要知道你对
i和d参数做了什么。
标签: c++ variadic-templates variadic-functions variadic