我创建了一个名为Course
、具有私有属性std::string code
的类,以及另一个名称为Student
、具有私有性质std::string id
的类。然后我创建了一个名为Enrollment
的类作为:
class Enrollment {
private:
Course course;
Student student;
public:
struct EnrHash {
size_t operator() (const Enrollment &__e) const {
auto _code = std::hash<std::string>() (__e.course.code);
auto _id = std::hash<std::string>() (__e.student.id);
return (_code ^ _id);
}
}
}
即使将course
和student
属性更改为protected,我也无法访问它们。我试过用course.getId()
替换它,但仍然不起作用。
我想了解为什么会这样,以及如何应对
谢谢:(
使struct EnrHash
成为Enrollment
:的friend
class Enrollment {
protected:
Course course;
Student student;
public:
friend struct EnrHash;
struct EnrHash {
…
};
}