프렌드 클래스
- 대상 클래스 내부에 friend 키워드로 선언
- 대상클래스의 객체처럼 모든 멤버에 접근 가능
class gs_engine : public ic_engine{
public:
gs_engine();
~gs_engine();
private:
void acceleration_output();
friend class automobile;
};
- 접근 지정자와 상관없이 automobile클래스 내부에서 gs_engine클래스의 모든 멤버 변수, 함수에 접근 가능
- automobile을 상속받은 클래스는 friend 속성 물려받지 않음
- 자식 클래스에서도 gs_engine 에 접근하게 허용하려면 friend 클래스로 선언해야 함
프렌드 함수
class gs_engine : public ic_engine{
public:
gs_egine();
~gs_engine();
private:
void acceleration_output();
friend class automobile;
friend void accelerator::acceleration_output(gs_engine & engine);
friend void acceleration_output_ex(gs_engine &engine) {...};
};