2009-05-30 4 views
0

이 함수 선언 내게 오류를 범 :이것이 왼쪽 스트림 연산자에 과부하가 걸리는 올바른 방법입니까? (C는 ++)

ostream& operator<<(ostream& os, hand& obj); 

오류는 :

error C2143: syntax error : missing ';' before '&' 
error C4430: missing type specifier 
error C2065: 'os' : undeclared identifier 
error C2065: 'obj' : undeclared identifier 
error C2275: 'hand' : illegal use of this type as an expression 
    see declaration of 'hand' 
error C4430: missing type specifier 

손 I가 이루어지는 클래스, 디스플레이 유형 char*의 공개 데이터의 부재이다.

아무도 내가 뭘 잘못하고 있다고 말할 수 있습니까?

답변

7

선언이 올바르게 보입니다. 그러나 오류 메시지는 ostream이 형식으로 알려져 있지 않음을 나타냅니다. iostream 헤더를 포함하고 대신 std::ostream라고 말하면됩니다.

고려해야 할 또 다른 사항은 'hand'매개 변수를 const 참조로 만드는 것입니다. 그래서 임시 직원도 받아 들여서 인쇄 할 수 있습니다.

2

헤더 안에 있습니까? 그렇다면 아마도 std::ostream라고 말할 필요가있을 것입니다. #include<iosfwd>을 확인하십시오.

또한 const hand&이라고 할 수 있습니다.

관련 문제