gpt4 book ai didi

c++ - 错误转换为请求的非标量类型

转载 作者:行者123 更新时间:2023-11-30 02:57:35 25 4
gpt4 key购买 nike

<分区>

我的错误:

In file included from Main.cpp:18:
QuickSort.h: In member function 'void CQuickSort<T>::Partition(std::vector<T, std::allocator<_CharT> >*, int, int, int) [with T = CMoviePointer]':
QuickSort.h:49: instantiated from 'void CQuickSort<T>::Sort(std::vector<T, std::allocator<_CharT> >*) [with T = CMoviePointer]'
Main.cpp:70: instantiated from here
QuickSort.h:31: error: conversion from 'std::vector<CMoviePointer, std::allocator<CMoviePointer> >' to non-scalar type 'CMoviePointer' requested
QuickSort.h:49: instantiated from 'void CQuickSort<T>::Sort(std::vector<T, std::allocator<_CharT> >*) [with T = CMoviePointer]'
Main.cpp:70: instantiated from here
QuickSort.h:35: error: no match for 'operator=' in '*(p_vec + ((long unsigned int)(((long unsigned int)upper) * 24ul))) = temp'
/usr/include/c++/4.4/bits/vector.tcc:156: note: candidates are: 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

我已经无计可施了。我不知道我做错了什么或实际问题出在哪里。非常感谢任何帮助

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com