4

单选题 4 /40

下面程序执行结果:
using namespace std; 
class A{ 
    public: 
        virtual void f() { cout << "A::f() "; } 
        void f() const { cout << "A::f() const "; } 
}; 
class B : public A { 
    public: 
        void f() { cout << "B::f() "; } 
        void f() const { cout << "B::f() const "; } 
}; 
void g(const A* a) { 
    a->f(); 
} 
int main(int argc, char *argv[]) { 
    A* p = new B(); 
    p->f(); 
    g(p); 
    delete(p); 
    return 0; 
}

参考答案

B::f() B::f() const
B::f() A::f() const
A::f() B::f() const
A::f() A::f() const