vector 正被转换为向量>
问题描述:
我创建了一个双向向量,然后尝试将其添加到我定义的对象中。问题是我的vector<double>
以某种方式转换为vector<double, allocator<double>>
。任何人都能看到为什么vector <double>正被转换为向量<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;
}
然后添加到我的对象时,我得到了以下错误:
no matching function for call to
generatorTemplate::generatorTemplate(std::string&, std::vector<double, std::allocator<double> >&......
答
std::vector<T>
事实上是一个template < class T, class Alloc = allocator<T> > class vector;
。正如你可以看到它有一个默认值的分配器类型参数。预计你会观察到什么。没有什么不妥。
在问题的正文中修正描述,似乎是不完整的wrt/subject。 – wilx 2013-03-17 10:56:42
你应该发布一些实际上重现问题的代码。 – juanchopanza 2013-03-17 11:05:10