首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >右值引用和文本

右值引用和文本
EN

Stack Overflow用户
提问于 2012-11-10 07:03:20
回答 1查看 219关注 0票数 4

考虑一下代码

代码语言:javascript
复制
template <typename... Args>
void foo (Args&& ...)
{
}

template <typename... Args>
void bar (Args&& ... args)
{
   foo (std::forward (args)...);
}

int main ()
{
  bar (true);
}
~                   

gcc 4.7.2给出了错误

代码语言:javascript
复制
error: no matching function for call to ‘forward(bool&)’
note: candidates are:

template<class _Tp> constexpr _Tp&& std::forward(typename std::remove_reference<_Tp>::type&)
note:   template argument deduction/substitution failed:

note: template<class _Tp> constexpr _Tp&& std::forward(typename std::remove_reference<_Tp>::type&&)
note:   template argument deduction/substitution failed:

为什么不将文字推导为右值?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-10 07:07:27

您没有正确使用std::forward():您需要将推导出的类型作为参数提供给std::forward()

代码语言:javascript
复制
foo (std::forward<Args>(args)...);
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13317312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档