Question

I'm creating a vector of doubles which I'm then trying to add to an object that I've defined. The problem is that my vector<double> is getting converted to a vector<double, allocator<double>> somehow. Can anyone see why?

#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;
}

Then when adding to my object I get the following error:

no matching function for call to generatorTemplate::generatorTemplate(std::string&, std::vector<double, std::allocator<double> >&......

Was it helpful?

Solution

std::vector<T> is in fact a template < class T, class Alloc = allocator<T> > class vector;. As you can see it has allocator type parameter with a default value. What you are observing is expected. There is nothing wrong with that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top