如何在c ++中编写最终方法,如java ..

如何在c ++中编写最终方法,如java ..

问题描述:

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

* 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



删除虚拟一词。


-

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

问:为什么这么糟糕?

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