【发布时间】:2016-08-26 19:01:00
【问题描述】:
我有一个对象“S”,它存储一个简单的指针元组,它通过使用可变参数模板变得灵活。有两种方法,store() 和 store2()。第一个(商店)工作正常。第二个无法编译,因为 std::make_tuple 失败并出现错误:
'没有匹配函数调用'make_tuple'
它进一步补充说,对于第一个参数,没有从 'B*' 到 'B*&&' 的已知对话(这个错误在元组库标题的深处)。
代码在这里:
#include <tuple>
#include <utility>
template<typename...Rs>
struct S
{
void store(std::tuple<Rs*...> rs)
{
rs_ = rs;
}
void store2(Rs*...rs)
{
rs_ = std::make_tuple<Rs*...>(rs...); // This is the guy that breaks
}
private:
std::tuple<Rs*...> rs_;
};
struct B
{};
struct A : S<B, B>
{};
int main()
{
auto *b1 = new B;
auto *b2 = new B;
auto *a1 = new A;
a1->store(std::make_tuple(b1, b2)); // This works
a1->store2(b1, b2); // How can I get this to work?
// (It causes an error in std::make_tuple of store2 above)
}
【问题讨论】:
-
FWIW,
std::make_tuple(rs...);为我工作。不过,我没有对该错误的解释。 -
谢谢——这对我也有用。
标签: c++ c++11 variadic-templates