private virtual in c++

 source from http://blog.csdn.net/steedhorse/article/details/333664

 

// Test.cpp   
#include <iostream>  
using namespace std;   
  
class Base {   
public:   
    void f() {   
        g();   
    }  
  
private:   
    virtual void g() {   
        cout << "Hi, MorningStar! I am g() of Base!." << endl;   
    }   
};  
  
class Derived : public Base {   
private:   
    virtual void g() {   
        cout << "Hi, MorningStar! I am g() of Derived." << endl;   
    }   
};  
  
int main() {   
    Base *pB = new Derived();   
    pB->f();   
    delete pB;   
    return 0;   
}  

  

posted @ 2014-09-27 11:56  Kstyjobx!!  阅读(660)  评论(0编辑  收藏  举报