繁体   English   中英

为什么std :: future模板参数类型是引用类型?

[英]why std::future template argument type is reference type?

我正在http://en.cppreference.com/w/cpp/thread/future上查看std::future文档

我不明白的是,为什么模板参数类型(在2 )是reference

 template< class T > class future<T&>; (2) (since C++11) 

这是std::future的参考专业,它说明了返回值是参考类型的情况。

例如,检查以下示例代码:

// future example
#include <iostream>       // std::cout
#include <future>         // std::async, std::future


int counter = 0;

int& increment_counter()
{
    return ++counter;
}

int main ()
{
    std::future<int&> fut = std::async(increment_counter); 

    int &counterRef = fut.get();

    std::cout << "value:" << counterRef << std::endl;

    return 0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM