친구 오퍼레이터 오버로드에 대해 혼란스러워합니다. 헤더 파일 내에 friend 연산자 오버로딩 함수를 작성하면 아무런 문제가 없지만 함수를 클래스 파일로 옮기면 다음과 같은 오류가 발생합니다. 내가 몇 가지 샘플을 봤 거든 그들은 모두 헤더 파일에 함수를 작성. 나는 무엇을 잘못 했는가? 감사. 당신이지고있어 오류 메시지에서C++ 친구 연산자 + 오버로드
...: error: expected ‘,’ or ‘...’ before ‘&’ token
...: error: ISO C++ forbids declaration of ‘statisticain’ with no type
...: error: ‘main_savitch_2C::statistician operator+(int)’ must have an argument of class or enumerated type
// a.h
class A
{
public:
friend A operator + (const A &a1, const A &a2);
};
// a.cpp
#include "a.h"
A operator + (const A &a1, const A &a2)
{
//
}
그 코드는 저에게 잘 작동합니다. ** 실제 ** 코드는 어떻게 생겼습니까? –
모두가 올바르게 연산자 +를 오버로드하는 방법에 대한 조언을 제공하기 때문에 [여기 있습니다] (http://codepad.org/8E9m5A7a) 내 조언. –