operator+ 정의부분에서 궁금한 것이 있습니다.
Cents operator+(const Cents& right_value)
{
return (this->cents_ + right_value.cents_);//추상적인 클래스는 return by reference가 불가능함!
}에서 교수님께서는 return Cents(this->cents_ + right_value.cents_); 라고 입력하셨는데, getCents()의 오버로딩을 통한 함수 호출이 아니라서 사실상 return 뒤에 Cents를 안 붙여도 정상적으로 작동하던데 이게 맞나요?두번째로, 다른 분들의 질문 글을 참조하였는데, 클래스를 반환하는 것이 아닌 아래와 같이 void를 반환하고friend void operator+(const Cents & c1, const Cents & c2)
{
cout << c1.m_cents + c2.m_cents << endl;
}
int main()
{
Cents cents1(6);
Cents cents2(8);
cents1 + cents2; // 14
도 정상적으로 작동하는데 클래스를 반환하는 것과 void를 반환하는 것중 어느게 더 속도가 빠른가요??마지막으로, non-member function으로 오버로딩을 할 때 cents1과 cents2는 각각 다른 주소에 멤버변수가 저장되어 있어서 operator+가 private에 접근하려면 friend를 선언해야 한다는 제 이해가 맞을까요??