dimanche 21 janvier 2018

storing functions in a std::vector works ok on linux but doesn't even compile on windows

This program that stores functions in a vector works with g++ 7.2.0 on linux but doesn't compile on windows with visual c++ 2017 v15.5.4 the error is for sin, cos, tan in the vector:

E0289 cannot determine which instance of overloaded function "sin" is intended. 

I don't see how to modify it so that it also works on windows.

#include <vector>
#include <cmath>
#include <functional>
#include <iostream>

typedef std::function<double(double)> AFunc;

std::vector<AFunc> funcs = {
  sin,
  cos,
  tan,
  [](double x) { return x*x; },
};

int main()
{
  std::cout << funcs[0](2) << std::endl;
  std::cout << funcs[1](2) << std::endl;
  std::cout << funcs[2](2) << std::endl;
  std::cout << funcs[3](2) << std::endl;

}

Aucun commentaire:

Enregistrer un commentaire