向量构造函数使用错误?

时间:2020-01-18 05:07:48

标签: c++ vector

我最近一直在从事一个学校项目,向我们介绍了Vectors。我还没有完全掌握它,但是我对它们的一般概念是向量非常类似于可以存储不同类型数据的二维数组。我在下面附加了一些代码,但出现以下错误:

没有构造函数实例“ std :: vector <_Ty,_Alloc> :: vector [带有_Ty = std :: vector >,_Alloc = std :: allocator >>]“

我不太确定我到底在哪里错,但这是函数和代码的声明。

//EFFECTS: returns a summary of the dataset as (value, frequency) pairs
//  In the returned vector-of-vectors, the inner vector is a (value, frequency)
//  pair.  The outer vector contains many of these pairs.  The pairs should be
//  sorted by value.
//  {
//    {1, 2},
//    {2, 3},
//    {17, 1}
//   }
//
// This means that the value 1 occurred twice, the value 2 occurred 3 times,
// and the value 17 occurred once
std::vector<std::vector<double> > summarize(std::vector<double> v);

我的代码:

vector<vector<double> > summarize(vector<double> v) {
    sort(v); //Sorts vector by values, rearranging from smallest to biggest.
    double currentVal = v[0];
    int count = 0;
    vector<pair<double,int>>vout = { {} };
    for (size_t i = 0; i < v.size(); i++) {
        if (v[i] == currentVal) {
            count++;
        }
        else {
            vout.emplace_back(make_pair(currentVal, count));
            currentVal = i;
            count = 1;
        }
    }
    vout.emplace_back(make_pair(currentVal, count));
    return { {vout} }; //Error here
}

在此感谢您的帮助以及对我在做什么的任何解释。如果需要更多信息,请告诉我。

0 个答案:

没有答案
相关问题