vector <double>被转换为vector <double,allocator <double =“”>&gt; </double,> </double>

时间:2013-03-17 10:55:23

标签: c++ vector double allocator

我正在创建一个双打矢量,然后我尝试添加到我定义的对象中。问题是我的vector<double>会以某种方式转换为vector<double, allocator<double>>。谁能明白为什么?

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;

double stringToDouble( const std::string& s )
{
  std::istringstream i(s);
  double x;
  if (!(i >> x))
    return 0;
  return x;
}

int main() {
    ifstream userDefine("userDefine.csv");
    string token, line;
    stringstream iss;
    int count = 0;
    vector<double> prices;

    while ( getline(userDefine, line) )
    {
        iss << line;
        while ( getline(iss, token, ',') )
        {
             double temp = stringToDouble(token);
             prices.push_back(temp);
        }
    }
    return 0;
}

然后在添加到我的对象时,我收到以下错误:

  

没有用于调用generatorTemplate::generatorTemplate(std::string&, std::vector<double, std::allocator<double> >&......

的匹配函数

1 个答案:

答案 0 :(得分:4)

std::vector<T>实际上是template < class T, class Alloc = allocator<T> > class vector;。正如您所看到的,它具有带有默认值的allocator类型参数。您所观察到的是预期的。这没什么不对。