1
2
对于眼前的问题,您可以将类_name()函数重命名为类_name_impl()或类似的函数,然后在基类中有一个类_name()函数调用实现函数。这样,在对派生对象调用class_name()时,只有基类版本匹配。 更一般地说,您可以通过在派生类中使用相同的命名函数来阻止调用基类方法的尝试—正如您所做的,但是任何人都可以强制转换为基类并调用他们喜欢的任何函数。不能停止在派生类中重写虚拟方法。。。你只能挫败他们的使用。 值得记住的是,公共派生类是基类的实例,应该提供基类的接口。 编辑:重做“现实世界的例子”编辑,你能用一个正常的实现来解释这个问题吗。。。
|
2
2
还没有添加C++ 11
http://en.wikipedia.org/wiki/C%2B%2B11#Explicit_overrides_and_final |
3
1
这也可以应用于虚拟方法:
|
4
0
|
5
0
看来你是想用一种很难的方式做点什么。 根据你想要达到的目标,以下可能是一个解决方案。
在上面的代码中,我假设它是用于调试/跟踪之类的。为了身份证的目的调查
|
rookie · 检查函数模板的所有参数包参数是否属于int 1 年前 |
ivaigult · -W转换和隐式字符串到布尔类型转换 1 年前 |
rainer · 后台插入程序的初始化 1 年前 |
Community wiki · 以理智、安全和高效的方式复制文件 1 年前 |
Shefali Kanaujia · 对C中向量的向量进行排序++ 1 年前 |
Ma Joonyoung · 粗粒度和细粒度链表的时间比较 1 年前 |