I know how to initilize a new vector before using it, but how to convenitently use it as paramter in a function? For example, when I init v1, it can get result in the end, but when I use v2, it shows error :cannot use this type name.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class Solution {
public:
vector<int> Add(vector<int>&nums, int target)
{
cout << nums[0] + target;
}
};
int main(){
Solution Sol1;
vector <int> v1 {1,2,3};
Sol1.add(v1, 8);
Sol1.add(vector <int> v2{4,5,6}, 8);
}
Besides, I tried to correct v2 as Sol1.add(vector <int> {4,5,6}, 8);
However, it shows error: The initial value of a non-constant reference must be an left value