腾讯2016春招实习生(软件开发)笔试模拟卷

#include <iostream>
#include <stdio.h>
using namespace std;

class A {
    public:
        A(){ cout << "A constru" << endl; }
        ~A(){ cout << "A xigou" << endl; }
};

class B: public A {
    public:
        B() { cout << "B contru" << endl; }
        ~B() { cout << "B xigou" << endl; }
};

struct SA {
    void foo(){ printf("foo "); }
    virtual void bar() { printf("bar "); }
    SA(){bar();}
};
struct SB: SA {
    void foo() { printf("b_foo "); }
    void bar() { printf("b_bar "); }
};

int main() {
    A *pA = new B();
    delete pA;
    SA *p = new SB;
    p->foo();
    p->bar();
    return 0;
}
/*
 *结果为:
A constru
B contru
A xigou
bar foo b_bar 
 */

原文地址:https://www.cnblogs.com/tenlee/p/5321389.html