변수가 개인용으로 사용되기 때문에 클래스의 개인 변수에 액세스 할 수없는 곳에서 내 operator<<
오버로드 문제가 있습니다. 컴파일러 오류.프렌드 연산자 << 오버로드 문제
std::ostream& operator << (std::ostream &out, const Library & l)
^^^^^^^^^^^^^
당신은을 반환해야합니다 library.h
이
#ifndef LIBRARY_H
#define LIBRARY_H
#define BookNotFound 1
#include "Book.h"
#include <iostream>
#include <cstdlib>
using namespace std;
namespace cs52{
class Library{
public:
Library();
void newBook(string title, string author);
void checkout(string title, string author) {throw (BookNotFound);}
void returnBook(string title, string author) {throw (BookNotFound);}
friend Library operator << (Library& out, const Library & l);
private:
Book myBooks[ 20 ];
int myNumberOfBooksSeenSoFar;
};
}
#endif
나는 그것이해야한다는 것을 알고있다. 그래서 나는 아직도 내 이름이 ... 컴파일시에 개인적이라고 말하기 때문에 혼란 스럽다. 도움이된다면 여기에 오류 코드가 있습니다. C : \ Users \ Devin \ Documents \ C++ SMCCLASS \ LibrarySystem \ library.h || 함수에서 'cs52 :: 라이브러리 연산자 << (std :: ostream &, const cs52 :: Library &)': | C : \ Users \ Devin \ Documents \ C++ SMCCLASS \ LibrarySystem \ library.h | 23 | 오류 : 'int cs52 :: Library :: myNumberOfBooksSeenSoFar'는 비공개 | –
@ 대븐 : 확실한가요? 함수 프로토 타입이 처음부터 올바르지 않습니다. –
@ 대변인 : 업데이트 된 답변을 확인하십시오. 귀하의 문제라고 생각합니다. 매개 변수 유형에주의하십시오! –