我的错误:
在 Main.cpp:18 包含的文件中:
QuickSort.h:在成员函数中'void CQuickSort<T>::Partition(std::vector<T, std::allocator<_CharT> >*, int, int, int) [with T = CMoviePointer]'
:
QuickSort.h:49:从'void CQuickSort<T>::Sort(std::vector<T, std::allocator<_CharT> >*) [with T = CMoviePointer]'
Main.cpp 实例化:70:从这里实例化
QuickSort.h:31:错误:从'std::vector<CMoviePointer, std::allocator<CMoviePointer> >'
非标量类型转换'CMoviePointer'
请求
的 QuickSort.h:49:从'void CQuickSort<T>::Sort(std::vector<T, std::allocator<_CharT> >*) [with T = CMoviePointer]'
Main.cpp 实例化:70:从此处实例化QuickSort.h:35:错误:在/usr/include/c++/4.4/bits/vector.tcc:156 中
不匹配 :注意:候选是:'operator='
'*(p_vec + ((long unsigned int)(((long unsigned int)upper) * 24ul))) = temp'
std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = CMoviePointer, _Alloc = std::allocator<CMoviePointer>]
这是我的程序。
#ifndef _QUICKSORT_H_
#define _QUICKSORT_H_
#include <vector>
template<class T>
class CQuickSort{
public:
void Partition(std::vector<T> *p_vec, int upper, int lower, int size){
if (size <2)
return;
int pivot_index = size/2;
pivot_index += lower;
while(lower < upper){ //do until start and end of list meet
while(p_vec[lower] < p_vec[pivot_index]){
lower--;
}
while(p_vec[pivot_index] < p_vec[upper]){
upper--;
}
T temp = p_vec[lower];
p_vec[lower] = p_vec[upper];
p_vec[upper] = temp; //swap upper and lower until lower is equal to or
}
}
void Sort(std::vector<T> *p_vec){
int size = p_vec->size();
if(size < 2)
return;
Partition(p_vec,0, size-1, size);
}
};
#endif
我无计可施。我不知道我做错了什么或实际问题出在哪里。任何帮助是极大的赞赏