0
안녕하세요 저는 바이너리 검색 트리에서 함수를 제대로 오버로드하는 방법을 궁금합니다. Heres는 코드는 내가 가진 : 함수를 제대로 오버로드하는 방법
int LessThan(E itm1, E itm2) {
if (itm1 < itm2) {return -1;}
else if (itm1 > itm2) {return 1;}
else if (itm1 == itm2) {return 0;}
}
int LessThan(string s1, string s2) { // Incase it is a string, we need to define <= and >= differently
return this->compare(s1, s2);
}
불행히도 나는 다음과 같은 오류를 받고 있어요 :
binarySearchTree.h:33:9: error: ‘int binarySearchTree<E>::LessThan(std::__cxx11::string, std::__cxx11::string) [with E = std::__cxx11::basic_string<char>; std::__cxx11::string = std::__cxx11::basic_string<char>]’ cannot be overloaded
int LessThan(string s1, string s2) { // Incase it is a string, we need to define <= and >= differently
^
binarySearchTree.h:27:9: error: with ‘int binarySearchTree<E>::LessThan(E, E) [with E = std::__cxx11::basic_string<char>]’
int LessThan(E itm1, E itm2) {
^
답변에 실제로 적절한 [mcve]가 포함되어야합니다. 클래스 템플릿의 멤버 함수는 ** 중요한 세부 사항 **입니다! – StoryTeller