如何在c ++中编写最终方法,如java .. [英] how write a final method in c++ like java ..

查看:42
本文介绍了如何在c ++中编写最终方法,如java ..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

B级

{

虚拟空虚m()

{


} < br $>
};


D级:公共B

{


}


应该做什么,以便无法在D中重写void m()

class B
{
virtual void m( )
{

}
};

class D : public B
{

}

what should be done so that void m() can not be overriden in D

推荐答案

* mangesh:
* mangesh:
B级
{
虚拟空间m()
{
}
};

D级:公共B


应该做什么,以便在D
class B
{
virtual void m( )
{
}
};

class D : public B
{
}

what should be done so that void m() can not be overriden in D


<中无法覆盖void m() br />
删除虚拟一词。


-

答:因为它弄乱了人们通常的顺序阅读文字。

问:为什么这么糟糕?

A:热门帖子。

问:什么是最烦人的usenet和电子邮件中的东西?



Remove the word ''virtual''.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


C ++不支持最终方法(比如Java)。


可以重新使用虚拟功能每当需要
时由派生类定义。没有办法限制此功能。

C++ doesn''t support final methods (like in Java).

A virtual function can be redefined by a derived class whenever
required. There is no way to restrict this functionality.


mangesh写道:
mangesh wrote:
B类
{
虚拟空间m()
{

}
};

D类:公共B
{

}
应该做什么,以便无法在D中覆盖void m()
class B
{
virtual void m( )
{

}
};

class D : public B
{

}

what should be done so that void m() can not be overriden in D


http://www.parashift.com/c++-faq-lit...html# faq-23.12


这篇关于如何在c ++中编写最终方法,如java ..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆