friend 클래스
friend는 클래스간 상호작용을 위해서 사용된다. 객체지향의 encapsulation 정의에 어긋나서 되도록 사용은 지양하지만 연산자 오버로딩에서 자주 쓰이곤 한다 #include using namespace std; class Time { friend class Date; private: int hour, min, sec; public: void setCurrentTime() { time_t currentTime = time(NULL); struct tm *p = localtime(¤tTime); hour = p->tm_hour; min = p->tm_min; sec = p->tm_sec; } }; class Date { private: int year, month, day; public:..
2019. 8. 12. 14:12