Type 을 리턴하는 것과 const Type 을 리턴하는 것
글쓴이: mmojz / 작성시간: 금, 2005/08/26 - 5:57오후
Type 을 리턴하는 것과 const Type을 리턴하는 것은 무슨 차이가 있을까요?
class A { private: Number m; public: Number ret(){return m;} // 혹은 const Number ret{...} }; int main() { A t; Number r = t.ret(); return 0; }
여기서 그냥 t.ret(); 을 하면 아무런 문제가 없겠지만 l-value 가 있다든지 이러면 차이가 나지 않을까요? 여러 방향으로 생각해도 잘 모르겠네요.
Number r = t.ret().GCD() = 10;
이런거 비슷하게 크게 생각하면.. 머리가 아프네요-_-;;;;;;;;;;;;;;;;;;;;
질문을 조잡하게 해서 뜻이 전달되었는가 모르겠네요...[/code]
Forums:
할당이야 우측의 값이 복사되는 거니까 상관없겠고,t.ret().X()
할당이야 우측의 값이 복사되는 거니까 상관없겠고,
t.ret().X() 식으로 사용할 수 있는 것이 const 멤버로 제한되지 않을까요?
댓글 달기