码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-08-29 12:41:00      阅读:453      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   strong   ar   div   cti   

 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 }

 

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

标签:style   blog   color   os   io   strong   ar   div   cti   

原文地址:http://www.cnblogs.com/disemboltura/p/3944543.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!