#include <iostream>
#include <vector>
#include <string>
class Doctor;
class Patient
{
friend void Doctor::MeetPatients();
public:
void MeetDoctors();
private:
std::string mName;
std::vector<Doctor*> mDoctors;
};
class Doctor
{
friend void Patient::MeetDoctors();
public:
void MeetPatients();
private:
std::string mName;
std::vector<Patient*> mPatients;
};
void Doctor::MeetPatients()
{
for (auto& patient : mPatients)
{
std::cout << "Meet patient : " << patient->mName << '\n'; // 여기 mName 접근이 안되유
}
}
void Patient::MeetDoctors()
{
for (const auto& doc : mDoctors)
{
std::cout << "Meet doctor : " << doc->mName << '\n'; // 여기는 잘 되는데 왜 위는 안되는거?
}
}
저기 주석 단 부분 friend 함수로 지정 해줬는데도 접근이 안된다고 에러 떠
아 ㅋㅋ
너 왕따
놀리지말고 좀 알려줘잉~
서로 friend 함수로 걸순없고, 한쪽은 함수, 한쪽은 클래스로 friend걸어줘야함.
9번째 줄을 friend class Doctor; 로 바꿔주면 해결됨.