int change(int x) { //this function works as transform last argument and multiplies all element of vector a by 10 and store them into b. x = x * 10; return x; } void change_ref(int &x) { //this function doesn't work as transform last argument. //error shown : binary =... no operator takes a right hand operand of type void ( or there is no acceptable conversion) // what i want to do is to pass by reference the values so that i dont have to return anything. x = x * 10; } int main() { vector<int>a = { 1,2,3 }; vector<int>b; transform(a.begin(), a.end(), back_inserter(b),change); for (int i = 0; i < b.size(); i++) { cout << b[i] << endl; } //b : {10,20,30} -->desired output. return 0; }
transform
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)