首页 > 解决方案 > 为什么使用显式模板参数调用 std::make_tuple() 会导致“无法将 'T*&&' 类型的右值引用绑定到 'T*' 类型的左值”错误?

问题描述

为什么我们在显式提供如下模板参数时会收到错误消息?

#include <tuple>
int main()
{
    int a = 1;
    int* ap = &a;
    // std::make_tuple<int*, int>(ap, a); // cause error "cannot bind rvalue reference of type 'int*&&' to lvalue of type 'int*'
    std::make_tuple(ap, a); // fine
}

标签: c++templates

解决方案


推荐阅读