[英]How to access a private property of a property in child struct const method?
I created a class named Course
with private property std::string code
and another class named Student
with private property std::string id
.我创建了一个名为Course
的 class 和私有属性std::string code
和另一个 class 名为Student
私有属性std::string id
。 Then I created a class named Enrollment
as:然后我创建了一个名为Enrollment
的 class 为:
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);
}
}
}
I can't access the course
and student
properties even after changing them to protected .即使将course
和student
属性更改为protected后,我也无法访问它们。 I have tried replacing it with course.getId()
but still not working.我尝试用course.getId()
替换它,但仍然无法正常工作。
I want to understand why that is and how to deal with it.我想了解为什么会这样以及如何处理它。
Thanks:)谢谢:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.