operator 연산자에 대한 질문입니다.
글쓴이: skylandi / 작성시간: 일, 2003/11/09 - 3:09오전
class Complex { private: int Read; int Imag; public: Complex(); Complex(Complex &); ~Complex(); void operator+=(Complex &addition); void operator-=(Complex &subtraction); void operator*=(Complex &multiply); void operator/=(Complex &dividing); void operator=(Complex &substitution); void Set(int a,int b); void Get(); int &a(int a); int &a(int a,int b); Complex &operator+(Complex &a); Complex &operator+(Complex &b,Complex &c); };
a는 function overloading 이 가능한데요
int &a(int a);
int &a(int a,int b);
Complex는 operator overloading이 가능 하지가 않습니다.
Complex &operator+(Complex &a);
Complex &operator+(Complex &b,Complex &c);
그런데 아래와 같이 frend 를 걸면 operator overloading이 가능 합니다.
그 이유가 무엇인지가 궁금 합니다.
Complex &operator+(Complex &a);
friend Complex &operator+(Complex &b,Complex &c);
좋은 하루 되시길...
Forums:
class 안에서 + operator를 overloading 할 경우 p
class 안에서 + operator를 overloading 할 경우 parameter는 1개 입니다.
Complex &operator+(Complex &a);
만 있다고 가정하면
이 것은
c = a.operator+(b);
로 이해하시면 됩니다. parameter가 2개일 수는 없지요.
friend Complex &operator+(Complex &b,Complex &c);
만 사용하셨다면
c = operator+(a, b);
가 되지요. 서로 overloading 되는 대상이 달라집니다.
그런데
이렇게 정의가 되면 실제 어떤 함수가 호출될지 될지 궁금하군요. :)
제가 알기론 아마먼저 클래스에서 미친듯이 찾고그 후에 글로벌에서
제가 알기론 아마
먼저 클래스에서 미친듯이 찾고
그 후에 글로벌에서 찾는 걸로 알고있습니다.
Stroustrup의 책을 본지 오래라 -_- 잘...
아무튼! 정해져 있습니다.
C++, 그리고 C++....
죽어도 C++
댓글 달기