gpt4 book ai didi

c++ - 没有匹配的函数调用未解析的函数类型

转载 作者:行者123 更新时间:2023-11-28 00:48:54 25 4
gpt4 key购买 nike

这段代码有问题,它说没有多次匹配的函数调用,尽管我使用相同的数据类型并且参数的数量相同,有人可以帮我吗?

#include <iostream>
#include <iterator>
#include <random>
#include <vector>
#include<list>
#include<deque>
#include <algorithm>
#include <chrono>
#include <functional>
#include <sstream>

using namespace std;
using namespace std::chrono;


template<typename F, typename Arg, typename T>
void times(F func, Arg A, int n, T typeval) // call func(arg,n, typeval)
{
auto t1 = system_clock::now();
func(A, n, typval);
auto t2 = system_clock::now();
auto dms = duration_cast<milliseconds>(t2-t1);
cout << "f(x) took " << dms.count() << " milliseconds\n";
}



int random_gen(int& i){
default_random_engine re { std::random_device()() };
uniform_int_distribution<int> dist;
auto r= bind(dist,re);
int x =r();
return x;
//return rand();
}

string random_gen(string& s)
{
string Result; // string which will contain the result
ostringstream convert; // stream used for the conversion
convert << rand();
return convert.str();
}

template<typename SequenceContainer, typename T>
void build_cont(SequenceContainer& seq, int n, T valtype)
{
for(int i=0; i!=n; ++i) {
T gen = random_gen(valtype);
typename SequenceContainer::iterator it = find_if(seq.begin(), seq.end(), [gen] (const typename SequenceContainer::reference & val) { return gen < val; } );
seq.insert(it, gen);
}
for(auto i:seq)
cout<<i<<endl;
}
int main() {
int n=10;
vector<int> v;
list<int>ls;
deque<int> deq;
cout<<"vector of int"<<endl;
times(build_cont, v, n, 0);

// string stemp = "";
// cout<<"vector of strings"<<endl;
// build_cont(sv, n, stemp);
// cout<<"list of strings"<<endl;
// build_cont(sls, n, stemp);
// cout<<"deque of strings"<<endl;
// build_cont(sdeq, n, stemp);
//
return 0;
}

当我运行 build_cont 时它运行得很好,但是当我把它放在 times 函数中时代码停止工作了?任何建议。

最佳答案

需要为build_cont指定模板参数

times(build_cont<std::vector<int>, int>, v, n, 0);

关于c++ - 没有匹配的函数调用未解析的函数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15084943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com