방금 질문이 있습니다. + = 연산자를 오버로드하여 문자열을 반환 할 수 있습니까? 여기에 내가 시도했지만, 성공하지 못했습니다.문자열을 반환하는 + = 연산자를 오버로드하는 방법은 무엇입니까?
// 'Student' is the class that this function is in
// 'get_name()' returns the name of the student
// 'get_grade()' returns the grade of the student
// Description:
// Ultimately I will be creating a list of students and their grades in
// the format of (Student1, Grade1) (Student2, Name2) ... (StudentN, GradeN)
// in a higher level class, and thus I need an overloaded += function.
Student& Student::operator+=(const Student& RHS)
{
string temp_string;
temp_string = "(" + RHS.get_name() + ", " + RHS.get_grade() + ") ";
return temp_string;
}
반환 형식을'std :: string'으로 변경 하시겠습니까? – NathanOliver
@ NathanOliver 당신은 어떻게 그 아이디어를 생각해 냈습니까? o_o – DeiDei
이것은 혼란스럽고 예상치 못한 일일 것임을 명심하십시오. 현재 오브젝트를 수정하는 것조차 보이지 않는 것 같습니다. 나는 이것을하지 않을 것을 제안 할 것이다. – Falmarri