C++子类中显式调用基类函数

 1 #include <iostream>
 2 using namespace std;
 3
 4 class thebase    {
 5 public:
 6     virtual void basePrint()    {
 7         cout << "the base class basePrint() function." << endl;
 8     }
 9
10     void basePrint2()    {
11         cout << "the base class basePrint2() function." << endl;
12     }
13
14 };
15
16 class thesub : public thebase{
17 public:
18     void basePrint()    {
19         cout << "i will call the parent function." << endl;
20         thebase::basePrint();  // 显式调用基类成员.  
21     }
22
23 };
24
25 int main(int argc, char* argv[])
26 {
27
28     thesub  mysub;
29     mysub.basePrint();
30
31     return 0;
32 }
时间: 2024-08-28 04:26:53

C++子类中显式调用基类函数的相关文章

【Python】Python中基类函数的重载和基类函数的调用

刚接触Python语言的时间不长,对于这个语言的很多特性并不是很了解,有很多用法都是还不知道.今天想着写一个Python面向对象编程时的继承中的函数调用.分享出来,一起进步. 因为之前接触过Java和C++,所有对于面向对象的思想也早已经很熟析的了.这里也不再对面向对象是什么进行赘述了.我们直接上代码吧!看看对于继承和基类函数的调用在Python中是如何调用的- 首先,是基类文件base.py ''' Created on Dec 18, 2014 @author: raul ''' class

C++中如何显式调用构造函数

#include <new> class A { public: A(); A(int); ... }; A * pA = (A *) malloc( sizeof(A) ); new (pA) A; // 调用A() A * pAA = (A *) malloc( sizeof(A) * 10 ); for (int i = 0; i < 10; ++i) new (pAA + i) A(i); // 调用A(int) 以上用法也称为放置构造,它是与第三方内存管理的标准接口,必须 in

C++中构造函数详解及显式调用构造函数

C++构造函数详解及显式调用构造函数 c++类的构造函数详解                        一. 构造函数是干什么的class Counter{public:         // 类Counter的构造函数         // 特点:以类名作为函数名,无返回类型         Counter()         {                m_value = 0;         }private:          // 数据成员         int m_val

在子类中显示父类的方法

用super 1 package ppt04; package ppt04; public class Ostrich extends Bird { // 重写Bird类的fly()方法 public void fly() { System.out.println("我只能在地上奔跑..."); } public void callOverridedMethod() { // 在子类方法中通过super来显式调用父类被覆盖的方法. super.fly(); } public stati

继承实现的原理、子类中调用父类的方法、封装

一.继承实现的原来 1.继承顺序 Python的类可以继承多个类.继承多个类的时候,其属性的寻找的方法有两种,分别是深度优先和广度优先. 如下的结构,新式类和经典类的属性查找顺序都一致.顺序为D--->A--->E--->B--->C. class E: def test(self): print('from E') class A(E): def test(self): print('from A') class B: def test(self): print('from B'

Scala 深入浅出实战经典 第51讲:Scala中链式调用风格的实现代码实战及其在Spark中应用

王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-64讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 腾讯微云:http://url.cn/TnGbdC 360云盘:http://yunpan.cn/cQ4c2UALDjSKy 访问密码 45e2土豆:http://www.tudou.com/programs/view/5uuKOP38d6s/优酷:http://v.youku.com/v_show/id_

C#中派生类调用基类构造函数用法分析

这里的默认构造函数是指在没有编写构造函数的情况下系统默认的无参构造函数 1.当基类中没有自己编写构造函数时,派生类默认的调用基类的默认构造函数例如: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 public class MyBaseClass { } public class MyDerivedClass : MyBaseClass {   public MyDerivedClass()   {    Console.WriteLine("我是子

关于C#中派生类调用基类构造函数的理解

(1)当基类中没有自己编写的构造函数时,派生类默认条用基类的构造函数 (2)当基类中有自己编写的构造函数时,要在基类中添加无参的构造函数 Java代码   public class MyBaseClass { public MyBaseClass() { } public MyBaseClass(int i) { Console.WriteLine("我是基类带一个参数的构造函数"); } } public class MyDerivedClass : MyBaseClass { pu

Day17:继承实现的原理、子类中调用父类的方法、封装

一.继承实现的原来 1.继承顺序 Python的类可以继承多个类.继承多个类的时候,其属性的寻找的方法有两种,分别是深度优先和广度优先. 如下的结构,新式类和经典类的属性查找顺序都一致.顺序为D--->A--->E--->B--->C. class E: def test(self): print('from E') class A(E): def test(self): print('from A') class B: def test(self): print('from B'