Need help figuring out why my code is having an issue, I'm sorting and mergeing two vectors but I'm getting an error with my function name I have it commented where the error is showing up. Can someone please explain why?
usingnamespace std;
vector<int> merge_sorted(vector<int> a, vector<int> b)
{
int i = 0, j = 0, p;
do
{
if( a[i]< b[j])
{
merge_sorted.push_back( a[i]);// I'm having errors with the merge_sorted part it says " error C2228: left of '.push_back' must have class/struct/union"
i += 1;
}
else
{
merge_sorted.push_back = (b[j]);
j += 1;
}
}
while ( i < a.size && j < b.size);
if (i < a.size)
for (p = i; p < a.size; p++)
merge_sorted.push_back (a[p]);
elsefor(p = j; p < a.size; p++)
merge_sorted.push_back (b[p]);
}
merge_sorted() is a function, not a class/structure/union. The way you have it written you should be using it like this (unfamiliar with templates as I'm fairly new myself so not certain about how to declare vectors):
1 2 3
vector<int> vec_1, vec_2, vec_2;
//set vec_2 and vec_3 to some values
vec_1 = merge_sorted(vec_2, vec_3);
Assuming push_back() is a member function of the vector class you use it like this: *something, maybe nothing* = vec_1.push_back(*argument(s)*)