现在的位置: 首页 > 综合 > 正文

C++中的私有virtual函数

2013年02月12日 ⁄ 综合 ⁄ 共 652字 ⁄ 字号 评论关闭

Java中的private函数是不能被继承的, 即基类中如果有一个private函数func(), 现在在子类中实现一个与其同名,参数列表也相同的func

()函数,这两个函数之间只是简单的覆盖关系,不能使用多态.

 

但是C++中可以被继承,使用多态性质.

 

 

打印结果:

callfunc() in Base.

this is func() in Base.

callfunc() in Base.

this is func() in derived1.

抱歉!评论已关闭.