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

时间:2014-08-29 12:41:00   收藏:0   阅读:453
 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 }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!