GriffTech

02-20-2004, 01:44 AM

Posted: Fri Feb 20, 2004 1:28 am Post subject: Templated function for vectors

--------------------------------------------------------------------------------

I am trying to write a templated function for vectors of different classes I have written. The templated function is an insertion sort, but I am gettign some binary errors. I have also overloaded the <, ==, << and >> operators within the Course class

Here is a bit of my code

template <typename T>

void insertSort(vector<T> vecArray);

within main I have declared a vector of type Course.

vector<Course> courseVec;

I have opened a file and filled the vector

I call the function

insertSort(courseVec);

here is my insertion code for the templated function

here is the errors I am gettting. Can anyone help

error C2678: binary '<' : no operator found which takes a left-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)

with

[

_Ty=Course

]

error C2678: binary '<' : no operator found which takes a left-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)

with

[

_Ty=Course

]

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::allocator<_Ty>::value_type' (or there is no acceptable conversion)

with

[

_Ty=Course

]

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)

with

[

_Ty=Course

]

template <typename T>

void insertSort(vector<T> vecArray)

{

vector<T> temp;

for(unsigned int i=0; i < vecArray.size(); i++)

{

temp = vecArray[i+1];

if(temp < vecArray[i])

{

for(int j=i; temp < vecArray[j] && j >=0; j--)

{

vecArray[j+1] = vecArray[j];

}

vecArray[j+1] = temp;

}

}

}

--------------------------------------------------------------------------------

I am trying to write a templated function for vectors of different classes I have written. The templated function is an insertion sort, but I am gettign some binary errors. I have also overloaded the <, ==, << and >> operators within the Course class

Here is a bit of my code

template <typename T>

void insertSort(vector<T> vecArray);

within main I have declared a vector of type Course.

vector<Course> courseVec;

I have opened a file and filled the vector

I call the function

insertSort(courseVec);

here is my insertion code for the templated function

here is the errors I am gettting. Can anyone help

error C2678: binary '<' : no operator found which takes a left-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)

with

[

_Ty=Course

]

error C2678: binary '<' : no operator found which takes a left-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)

with

[

_Ty=Course

]

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::allocator<_Ty>::value_type' (or there is no acceptable conversion)

with

[

_Ty=Course

]

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)

with

[

_Ty=Course

]

template <typename T>

void insertSort(vector<T> vecArray)

{

vector<T> temp;

for(unsigned int i=0; i < vecArray.size(); i++)

{

temp = vecArray[i+1];

if(temp < vecArray[i])

{

for(int j=i; temp < vecArray[j] && j >=0; j--)

{

vecArray[j+1] = vecArray[j];

}

vecArray[j+1] = temp;

}

}

}