c++STL transform函数报错,求解
#include <iostream>#include <string>
#include "vector"
#include "algorithm"
using namespace std;
template<typename T>
class SumAdd
{
public:
T operator()(T t1, T t2)
{
return (t1 + t2);
}
private:
};
int main()
{
vector<int> v1, v2;
vector<int> v3;
v1.push_back(1);
v1.push_back(2);
v1.push_back(3);
v2.push_back(5);
v2.push_back(6);
v2.push_back(7);
transform(v1.begin(), v1.end(), v2.begin(), v3.begin(), SumAdd<int>());
for (vector<int>::iterator it = v3.begin(); it != v3.end(); it++)
{
cout << *it << endl;
}
system("pause");
return 0;
}
编译器是vs2017. #include <iostream>
#include <string>
#include "vector"
#include "algorithm"
using namespace std;
template<typename T>
class SumAdd
{
public:
T operator()(T t1, T t2)
{
return (t1 + t2);
}
private:
};
int main()
{
vector<int> v1, v2;
vector<int> v3(3);
v1.push_back(1);
v1.push_back(2);
v1.push_back(3);
v2.push_back(5);
v2.push_back(6);
v2.push_back(7);
transform(v1.begin(), v1.end(), v2.begin(), v3.begin(), SumAdd<int>());
for(vector<int>::iterator it = v3.begin(); it != v3.end(); it++)
{
cout << *it << endl;
}
system("pause");
return 0;
}
vector<int> v3(3);
页:
[1]