jeudi 25 mars 2021

Candidate expects 5 arguments for transform function

Please help me with this std::transform, the error is "candidate expects 5 arguments, 4 provided". What could cause this issue ?

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct X 
{
  X(int x):x_(x)
  {}
  int x_;  
};

int main()
{   
    X x(1); 
    X x1(2);
    X x2(3);
    std::vector<X> v;
    v.emplace_back(x);
    v.emplace_back(x1);
    v.emplace_back(x2);
    std::vector<X> v2;
    std::transform(v.begin, v.end(), std::back_inserter(v2),
        [](X x1)
        {
            return x1.x_ * 100;
        });
    
    for (auto& i: v2)
    {
        std::cout<<i.x_<< " ";
    }
    return 0;
}

Thank you.

Aucun commentaire:

Enregistrer un commentaire