2013-04-22 7 views
0

나는 컴파일을 시도해 왔으며 앰퍼샌드로 놀았지만 여전히 오류가 무엇인지 알 수 없다. 어떤 아이디어?int *에서 int로 변환 &

qsort.cc:22:23: error: no matching function for call to ‘qsort<int>::quicksort(std::vector<int, std::allocator<int> >*)’ 
qsort.cc:22:23: note: candidate is: 

qsort.h:16:6: note: void qsort<T>::quicksort(std::vector<T>&) [with T = int] 
qsort.h:16:6: note: no known conversion for argument 1 from ‘std::vector<int, std::allocator<int> >*’ to ‘std::vector<int, std::allocator<int> >&’ 

헤더 :

template <class T> 
class qsort 
{ 
public: 

void quicksort(vector<T> &v); 
void qusort(vector<T> &v, int left, int right); 
void print(vector<T> &v); 
}; 

template <class T> 
void qsort<T>::quicksort(vector<T> &v) 
{ 
qusort(&v, 0, 0); 
} 

template <class T> 
void qsort<T>::print(vector<T> &v) 
{ 
    for(int i = 0; i < v.size(); i++) 
    { 
    cout << v[i] << endl; 
    } 
} 

홈페이지 :

int main() 
{ 
qsort<int> asort; 
vector<int> v; 

v.push_back(2); 
v.push_back(1); 
v.push_back(7); 
v.push_back(3); 
v.push_back(8); 
v.push_back(4); 
v.push_back(0); 
v.push_back(9); 
v.push_back(5); 
v.push_back(6); 

asort.quicksort(&v); 
asort.print(&v); 

return 0; 
} 

업데이트 오류 주 함수 호출 (짧은 버전)

qsort.h에서 제거 앰퍼샌드 : 회원에서 함수 'void quisort :: qusort (std :: vector &, int, int) [T = int]'포함 :,451,515,qsort.h : 18 : 5 :에서 인스턴스화 '무효 quisort :: 퀵 (STD : 벡터 &)과 T = INT]

qsort.cc:22:22 : 여기에서 인스턴스화 qsort.h : 27 : 38 : 오류 : 'int'에서 'const char *'로의 변환이 잘못되었습니다. [-fpermissive] /usr/include/c++/4.6/bits/basic_string.tcc:214:5 : 오류 : '' [_CharT = CHAR, _Traits = 표준 : char_traits, _Alloc = 성병 :: 할당] 표준 : < _CharT, _Traits을 basic_string, _Alloc> :: basic_string (CONST _CharT * CONST _Alloc &) '[-fpermissive]

qsort.h : 18 : 5 : 'void quisort :: quicksort (std :: vector(& v) -> std :: 31 : 9 : 오류 : '<'의 '연산자'와 일치하지 않음 : qsort.cc:22:22 : 여기에서 인스턴스화 됨 qsort.h : 벡터 < _Tp, _Alloc> :: operator [] [_Tp = int, _Alloc = std :: allocator, std :: vector < _Tp, _Alloc> :: 참조 = int &, 표준 :: 벡터 < _Tp, _Alloc> : : size_type = long unsigned int] (((long unsigned int) i)) < 피벗 ' qsort.h : 31 : 9 : 참고 : 후보자는 다음과 같습니다. /usr/include/c++/4.6/bits/stl_pair.h : 207 : 5 : 참고 : 템플릿 bool std :: operator < (const std :: pair < _T1, _T2> &, const std :: pair < _T1, _T2> &) /usr/include/c++/4.6/bits/stl_iterator.h:291:5 : 참고 : 템플릿 부울 표준 : 운영자 < (const를 표준 :: reverse_iterator < _Iterator> &, const를 표준 :: reverse_iterator < _Iterator> &)

+0

사이드 참고 : 이름이'qsort' 이미 표준 라이브러리에 의해 점유되어 있기 때문에, 당신은 당신의 클래스 이름을 변경하거나 네임 스페이스에 넣어 권합니다 ['std :: qsort'] 구현 (http://en.cppreference.com/w/cpp/algorithm/qsort). – WhozCraig

+0

@WhozCraig 고맙습니다. 나는 그것을 깨닫지 못하고 변경했습니다. – user2057191

답변

1

멤버 함수는 인수를 참조로 사용합니다. 포인터 (주소 연산자 &에 의해 반환되는 포인터)를 사용하지 않습니다. 당신은 단순히 객체를 전달해야하고, 참조 바인딩 :

asort.quicksort(v); 
asort.print(v); 
+0

문제는 제거 할 때 더 많은 변환 오류가있는 대량 오류 블록이 발생합니다. – user2057191

+0

@ user2057191 무엇이 오류입니까? – 0x499602D2

+0

메인 포스트를 새로운 오류로 업데이트했습니다. – user2057191