연산자 오버로딩 질문 좀 ㅠㅠ
등대
타입의 다른 두 객체를 비교 연산하기 위해 ..
와 를 재정의하려는데요 ..
class t1
{
private:
/* ... */
public:
/* ... */
bool operator(const t2& obj) const ; // t2타입은 unknown 상태이므로오류
bool operator(const t2& obj) const ; // 위와 같은 이유로 오류 ..
};
class t2
{
private:
/* ... */
public:
/* ... */
bool operator(const t1& obj) const ;
bool operator(const t1& obj) const ;
};
main()
{
t1 obj1 ;
t2 obj2 ;
if(obj1 obj2)
//...
if(obj1 obj2)
//...
if(obj2 obj1)
//...
if(obj2 obj1)
//...
}
다른 방법으로 ..
클래스에 오퍼레이터 메소드를 두지 않고 ..
외부에 함수로두면 ..
클래스의 private 멤버에 접근할 수가 없는데요 ..
그렇다고, 프렌드로 지정하면..
class t1{
// ..
friend bool operator(const t1& , const t2&) ; // 역시 .. t2타입은 unknown 상태
friend bool operator(const t1& , const t2&) ; // 이므로 오류 발생 ...
// ..
};
class t2{
// ..
friend bool operator(const t2& , const t1&) ;
friend bool operator(const t2& , const t1&) ;
// ..
};
역시 오류가 납니다 .
타입이 다른 두 객체(t1 객체와 t2 객체)를 비교할 때 ..
과 는 어떤식으로오버로딩 가능한지 좀 알려주셔요 .