0
我在看在http://en.cppreference.com/w/cpp/thread/future爲什麼std :: future模板參數類型是引用類型?
的std::future
文檔我不明白的是,爲什麼(在2
)模板參數類型爲reference
?
template< class T > class future<T&>; (2) (since C++11)
我在看在http://en.cppreference.com/w/cpp/thread/future爲什麼std :: 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;
}
它是引用類型的局部特化。 – Barry
明白了。謝謝。 – Monku