要求基类成员由派生类填充

要求基类成员由派生类填充

本文介绍了要求基类成员由派生类填充。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个基类必须有一个成员变量填充,并且只有派生类 。 如果我宣布变量为内部受保护那么 基类*可以*填充变量,但派生类不需要* (必须是这种情况)。 如果我在 基类中创建一个填充成员变量的抽象方法,那么满足要求的是什么。在这种情况下,实现该方法需要派生的 类。 是否有其他方法可以满足要求?...特别是成员 基类变量*必须*由派生类填充(并且仅由 派生类填充)? 谢谢!I have a base class that must have a member variable populated by, and onlyby, derived classes.It appears that if I declare the variable as "internal protected" then thebase class *can* populate the variable, but the population is not *required*by the derived class (which must be the case).What would meet the requirements is if I create an abstract method in thebase class that populates the member variable. In this case the derivedclasses would be required to implement the method.Is there another way to meet the requirement?... specifically that a membervariable of a base class *must* be populated by a derived class (and only byderived classes)?Thanks!推荐答案 这篇关于要求基类成员由派生类填充。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-14 04:52