ms的一道C++题

#include <iostream>

using namespace std;

class A  
{  
public:  
    virtual void f()  
    {  
        cout<<"A::f()"<<endl;  
    }  
    void f() const  
    {  
        cout<<"A::f() const"<<endl;  
    }  
};  

class B: public A  
{  
public:  
    void f()  
    {  
        cout<<"B::f()"<<endl;  
    }  
    void f() const  
    {  
        cout<<"B::f() const"<<endl;  
    }  
};  
      
void g(const A* a)  
{  
    a->f();  
}  
  
int main()  
{  
    A* a = new B();  
    a->f();  
    g(a);  
    delete a ;  
}  

输出是:

 

posted @ 2014-09-23 15:06  独墅一枝花  阅读(118)  评论(0编辑  收藏  举报