育儿班 [英] Parenting class
本文介绍了育儿班的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这只企鹅是鸟吗? :)
[包含广告的小企鹅图片已被删除]
请
有什么想法可以防止使用其fly()
函数吗? :)
Is this pinguin a bird ? :)
[a picture of the pinguin, containing also advertising, has been removed]
Please
any idea to prevent the usage of its fly()
function ? :)
class bird
{
...
public:
...
virtual void fly();
};
class pinguin : public bird
{
...
};
推荐答案
class pinguin : bird
{
new private void fly() { }
}
fly方法将是私有的,即无法从任何实现中访问.
The fly method will be private, i.e. not accessible from any implementation.
Hmm ... :)
Hmm... :)
bird theBird;
pinguin thePinguin;
covey theCovey;
theCovey.add(theBird);
theCovey.add(thePinguin);
bird* pBird = theCovey.GetFirstBird();
while (pBird) {
pBird->fly();
// now is here a pinguin, a bird as well... :)
pBird = theCovey.GetNextBird();
}
这篇关于育儿班的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文