수 없이 듣는 질문중에 하나인데,
버그(bug)입니다. 서비스 팩을 ms 웹사이트 가서 다운 받아 설치하시던지,
아님 다른 컴파일러를 쓰시던지,
김대영 님이 쓰신 글 :
: 안녕하세요 고수님의 도움을 기다립니당.
:
: vc++ 6.0을 쓰는데요... 클래스에서 프렌드로 선언한 함수가
: private 개별 멤버를 access 할 수 없다고 나오네요 왜 그러죵?
:
: 헤더파일
: 에서... 프렌드 부분 거의 아래쪽 보세요
:
: // stonewt.h -- definition for Stonewt class
: #ifndef _STONEWT_H_
: #define _STONEWT_H_
: class Stonewt
: {
: private:
: enum {Lbs_per_stn = 14}; // pounds per stone
: int stone; // whole stones
: double pds_left; // fractional pounds
: double pounds; // entire weight in pounds
: public:
: Stonewt(double lbs); // constructor for double pounds
: Stonewt(int stn, double lbs); // constructor for stone, lbs
: Stonewt(); // default constructor
: ~Stonewt();
: void show_lbs() const; // show weight in pounds format
: void show_stn() const; // show weight in stone format
: bool operator <(const Stonewt& st) const;
:
: -->>이부분 friend ostream& operator<<(ostream& os, const Stonewt& st);
:
: };
: #endif
:
: 이렇게 선언하구 다음과 같이 정의를 했는데...
:
:
:
: ostream& operator<<(ostream& os, const Stonewt& st)
: {
: os<<st.pounds;
: return os;
: }
:
:
: 컴파일하니까 다음과 같이 에러가 뜨네요...
:
: --------------------Configuration: stone - Win32 Debug--------------------
: Compiling...
: stone.cpp
: stonewt.cpp
: C:\My Documents\Cpp\Listings\L10-10\stonewt.cpp(54) : error C2248: 'pounds' : cannot access private member declared in class 'Stonewt'
: c:\my documents\cpp\listings\l10-10\stonewt.h(10) : see declaration of 'pounds'
: Error executing cl.exe.
:
: stone.exe - 1 error(s), 0 warning(s)
:
: 왜 그러죠?? 도무지 이해를 할수 가 없어서 이렇게 고수님께 도움부탁해요
: 제가 아는 상식에선 프렌드 함수는 public 멤버함수와 더불어 유일하게 클래스의 private 멤버에 접근 할 수 있는 것이라 알았는데..막상 컴파일하니까 이렇게 에러가 뜨네요..도와주세요!~
:
: 그럼 답변기다릴께요~~
:
|