C++ 형변환 연산자 오버로딩
-
게시물 수정 , 삭제는 로그인 필요
class opt_test {
private:
int x;
int y;
public:
opt_test();
opt_test(int _x, int _y);
opt_test(const opt_test& _opt);
~opt_test();
inline int GetX() { return x; }
inline int GetY() { return y; }
public: // Operator
operator int();
operator float();
operator double();
};
다음과 같이
operator int();
operator float();
operator double();
이 형변환 연산자를 정의하려고 합니다.
다른 연산자 오버로딩은 어떻게 끝냈는데, 형변환 연산자 오버로딩을 공부하다가
책에서 단순히 멤버변수가 한가지일 경우의 예제밖에 안나와 있어서 질문드립니다.
그냥 한가지 멤버변수가 있을때는 한가지 멤버변수만 return하면 되지만
두가지일 경우에는 어떻게 하나요?
반환은 하나만 되는거 아닌가요?
저렇게 x,y 가 두가지일 경우에는 어떤식으로 정의를 해야하는지 궁금합니다.
#c++ vector #c++ string #c++ map #c++ sort #c++ 연산자 #c++ set #c++ 배열 #c++ int to string #c++ 포인터 #c++ queue