I'm making a merge sort class that has functions that take in a vector, sort it and return it. It looks like this:
class MergeSort {
public:
template <class T>
static vector<T> sort (vector<T> a)
{
if (a.size()<=1)
{
return a;
}
else
{
//some code here(seperating the vector
vector<T> left=sort(leftVec);//recursive call
vector<T> right=sort(rightVec);//recursive call
vector<T>FinalVec;//this will be the final vector that is returned
FinalVec=merge(left,right);//will merge and sort when all the vectors
//getting issues here^^^^^
return FinalVec;
}
}
private:
template <class T>
vector<T> merge (vector<T> left,vector<T> right)
{
//some code here
return final;
}
};
Issue i'm getting is when I try to do
**FinalVec=merge(left,right);
Error i'm getting is:
error: cannot call member function ‘std::vector MergeSort::merge(std::vector, std::vector) [with T = int]’ without object FinalVec=merge(left,right);//
In my main i try to do:
vector gooz;
gooz.push_back(7);
gooz.push_back(5);
gooz.push_back(4);
gooz.push_back(3);
gooz.push_back(2);
gooz.push_back(1);
gooz=MergeSort::sort(gooz);
//or even using it on an object of MergeSort won't work;
Thanks!