C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[24510] "STL 관련 질문" 다음 소스가 컴파일 되지 않는 이유가 무엇입니까?
김성철.마법사 [douner] 680 읽음    2003-02-26 21:06
//---------------------------------------------------------------------------
#include <iostream>
#include <list>
#include <string>
#pragma hdrstop

//---------------------------------------------------------------------------
using namespace std;

class MailList
{
private:
    string name;
    string street;
    string city;
    string state;
    string zip;
public:
    MailList()
    {
        name = street = city = state = zip = "";
    }
    MailList(string n, string s, string c, string st, string z)
    {
        name = n;
        street = s;
        city = c;
        state = s;
        zip = z;
    }

    string getName() { return name; }
    string getCity() { return city; }
    string getStreet() { return street; }
    string getState() { return state; }
    string getZip() { return zip; }
};
bool operator<(MailList &a, MailList &b)
{
    return a.getName() < b.getName();
}

bool operator==(MailList &a, MailList &b)
{
   return a.getName() == b.getName();
}

void display(list<MailList> &lst)
{
    list<MailList>::iterator p;

    for(p=lst.begin(); p!=lst.end(); p++)
    {
        cout << p->getName() << ": ";
        cout << p->getStreet() << ", ";
        cout << p->getCity() << ", ";
        cout << p->getState() << ", ";
        cout << p->getZip() << "\n";
    }
}
int main()
{
    list<MailList> mlstA;

    mlstA.push_back( MailList("James, Tom", "1102 W. Henry st", "Mission", "TX", "78572") );
    mlstA.push_back( MailList("김성철","둔전리","용인","시","449812") );
    mlstA.push_back( MailList("이동철","용인", "용인","시","449812") );

    mlstA.sort();
    display(mlstA);

    system("PAUSE");
    return 0;
}

//---------------------------------------------------------------------------

를 컴파일하면

[C++ Error] _function_base.h(73): E2093 'operator<' not implemented in type 'MailList' for arguments of the same type

의 에러가 출력됩니다.

template <class _Tp>
struct less : public binary_function<_Tp,_Tp,bool>
{
  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
};

list 의 sort 멤버 함수가 내부에서 '<' 연산자를 사용할텐데요

그래서 클래스를 변수들을 비교하기 위한 연산자들을 만들어 주었는데...

bool operator<(MailList &a, MailList &b) 가 쓰이질 않고 less 라는 함수객체가 사용되는 것인가요?

참고로 타 컴파일러에서는 문제없이 컴파일됩니다.

답변해 주시면 정말 고맙겠습니다 ^___^

+ -

관련 글 리스트
24510 "STL 관련 질문" 다음 소스가 컴파일 되지 않는 이유가 무엇입니까? 김성철.마법사 680 2003/02/26
24511     Re: 생성자를 옳게 고치니 되는군요. 김백일.cedar 690 2003/02/26
24514         Re:Re: 생성자를 옳게 고치니 되는군요. 김성철.마법사 646 2003/02/26
24520             Re:Re:Re: 저의 착각이었네요. ^^; 김백일.cedar 609 2003/02/27
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.