最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++17 - Curious about this detail, rvalue vs const ref - Stack Overflow

programmeradmin1浏览0评论

In this simple example r-value ref is preferred.

int f(const std::string& str)
{
    return 1;
}

int f(std::string&& str)
{
    return 2;
}

int main()
{
    std::cout << f("Hello!") << std::endl;
}

My c++11 gut tells me I'd go for the const ref version.

Is there a compelling reason why the r-value ref version is preferred?

I thought we liked the constness of the first version.

发布评论

评论列表(0)

  1. 暂无评论