亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区
Chinaunix
標(biāo)題:
template<typename>不能推導(dǎo)出指針類(lèi)型嗎?
[打印本頁(yè)]
作者:
asker160
時(shí)間:
2016-06-18 20:01
標(biāo)題:
template<typename>不能推導(dǎo)出指針類(lèi)型嗎?
本帖最后由 asker160 于 2016-06-18 20:05 編輯
下面一個(gè)例子程序,編譯運(yùn)行沒(méi)有問(wèn)題。
#include <thread>
#include <future>
#include <iostream>
#include <algorithm>
void f(int* first,
int* last,
std::promise<int> accumulate_promise)
{
int sum = std::accumulate(first, last, 0);
accumulate_promise.set_value(sum); // Notify future
}
int main()
{
int numbers[] = { 1, 2, 3, 4, 5, 6 };
std::promise<int> accumulate_promise;
std::future<int> accumulate_future = accumulate_promise.get_future();
std::thread work_thread(f, begin(numbers), end(numbers),
std::move(accumulate_promise));
accumulate_future.wait(); // wait for result
std::cout << "result=" << accumulate_future.get() << '\n';
work_thread.join(); // wait for thread completion
}
復(fù)制代碼
但是如果我把f函數(shù)改成模板的形式,如下:
template<typename Iterator>
void f(Iterator first,
Iterator last,
std::promise<int> accumulate_promise)
{
int sum = std::accumulate(first, last, 0);
accumulate_promise.set_value(sum); // Notify future
}
復(fù)制代碼
就會(huì)編譯不過(guò),說(shuō)thread::thread構(gòu)造函數(shù)找不到這樣的重載。
error: no matching function for call to 'std::thread::thread(<unresolved overloaded function type>, int*, int*, std::remove_reference<std::promise<int>&>::type)'
這個(gè)錯(cuò)誤是什么含義? 我的模板用法不對(duì)嗎?
謝謝。
作者:
windoze
時(shí)間:
2016-06-20 01:18
template<typename Iterator>void f(...)
復(fù)制代碼
這玩意兒不是個(gè)function,是個(gè)function template。
歡迎光臨 Chinaunix (http://72891.cn/)
Powered by Discuz! X3.2