标签:
1 #include <iostream> 2 3 using namespace std; 4 class Base{ 5 public: 6 Base(int i):b_number(i){} 7 int get_number()const{return b_number;} 8 void print(){ 9 cout<<b_number<<endl; 10 } 11 //private: 12 protected: 13 int b_number; 14 }; 15 class Derived:public Base{ 16 public: 17 Derived(int i,int j):Base(i),d_number(j){} 18 void print(){ 19 // cout<<get_number()<<" "; 20 cout<<b_number<<" "; 21 cout<<d_number<<endl; 22 } 23 private: 24 int d_number; 25 }; 26 int main(int argc, const char * argv[]) { 27 Base a(2); 28 Derived b(3,4); 29 cout<<"a is "; 30 a.print(); 31 cout<<"b is "; 32 b.print(); 33 cout<<"base part of b is "; 34 b.Base::print(); 35 return 0; 36 }
标签:
原文地址:http://www.cnblogs.com/cai1432452416/p/5218533.html