
我原来有一个简单的(不那么优雅)
class Shell{ public: bool checkThing(); // etc... private: bool _thing;};class Action{ public: virtual voID execute( Shell &s )=0;};class ChangeAction : public Action{ public: voID execute( Shell &s ) { // requires frIEndship or public mutator! s._thing = true; }}; 所以我考虑了一个嵌套类Action,但我想把它变成私有的(为什么让其他人做除了Shell之外的具体动作,对吧?)
class Shell{ public: bool checkThing(); // etc... private: bool _thing; class Action;};class Shell::Action{ public: virtual voID execute( Shell &s )=0;};class ChangeAction : public Shell::Action{ public: voID execute( Shell &s ) { // ok Now! s._thing = true; }}; 但是我当然不能继承Action了(这是有道理的,它是私有的).所以这不起作用.
所以我的问题,我应该采用第一种方法和友谊还是公共界面?我可以使用类似于第二种方法的东西来保持与Actions和Shell的关系吗?
你有更好的主意吗?
很棒的问题,顺便说一下!
总结以上是内存溢出为你收集整理的C私有嵌套抽象类全部内容,希望文章能够帮你解决C私有嵌套抽象类所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)