c++ - 将元组的 const 引用传递给仿函数

标签 c++ constants pass-by-reference thrust

我有一个 functor 需要修改元组值。所以我将 const reference 传递给它。

这是我的代码:

void operator() (thrust::tuple<const int&,const float&> tup)
{
    thrust::get<1> (tup) += 10;
    thrust::get<0> (tup) += 10;

}

但是我得到一个错误: 错误:表达式必须是可修改的左值 显然我没有修改引用,我只是修改元组引用的值。

最佳答案

..which needs to modify tuple values. So I am passing a const..

不要传递 const,你会没事的。

关于c++ - 将元组的 const 引用传递给仿函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36843441/

相关文章:

C++11 和 Visual Studio - 未解析的外部符号

c++ - 为什么 QVector<TYPE*​​>::contains 期望指向非常量 TYPE 的指针作为其参数?

c++ - 在 const 成员函数中返回 C++ 引用

c++ - 理解递归中的引用参数

c - 通过引用传递动态结构? [C]

linux - pThread 函数参数,向每个线程发送相同的值,等待其他内容

c++ - mno-cygwin 在构建 C++ 库时出现无法识别的命令行选项错误

c++ - Fortran 到 C 库的链接器错误 -/usr/lib/libf2c.so : undefined reference to 'MAIN__'

c++ - 即使在修复泄漏后,Valgrind 仍显示相同的内存泄漏

c++ - 对具有可变成员的对象的 const 引用