Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[2622] [질문] c++ 에서 프렌드에 관한건데요..아래꺼랑 비슷한 질문인데요...
김대영 [hyangil] 1043 읽음    2003-05-16 01:27
안녕하세요 고수님의 도움을 기다립니당.

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 멤버에 접근 할 수 있는 것이라 알았는데..막상 컴파일하니까 이렇게 에러가 뜨네요..도와주세요!~

그럼 답변기다릴께요~~

+ -

관련 글 리스트
2622 [질문] c++ 에서 프렌드에 관한건데요..아래꺼랑 비슷한 질문인데요... 김대영 1043 2003/05/16
2626     Re:bug... fiten 968 2003/05/16
2627         Re:Re:bug... 감사합니당..역시 버그 였나봐요..서비스팩 다시 깔았더니 되네요 고맙습니당. ^^ 냉무 김대영 1006 2003/05/16
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.