C++ 加法函数重载?

C++ 加法函数重载?,c++,inheritance,overloading,C++,Inheritance,Overloading,假设我有一个基类和一个派生类: struct A { void foo() { std::cout << "Do one thing." << std::endl; } }; struct B: public A { void foo() { std::cout << "Do another thing." << std::endl; } }; B myB; myB

假设我有一个基类和一个派生类:

struct A
{
    void foo()
    {
        std::cout << "Do one thing." << std::endl;
    }
};

struct B: public A
{
    void foo()
    {
        std::cout << "Do another thing." << std::endl;
    }
};

B myB;
myB.foo();
B::foo()
中调用
A::foo()
,这样基类的函数将首先执行,然后派生类函数的其余部分执行

struct A
{
    void foo()
    {
        std::cout << "Do one thing." << std::endl;
    }
};

struct B : public A
{
    void foo()
    {
        A::foo();
        std::cout << "Do another thing." << std::endl;
    }
};
结构A { void foo() { std::cout在
B::foo()
中调用
A::foo()

struct A
{
    void foo()
    {
        std::cout << "Do one thing." << std::endl;
    }
};

struct B : public A
{
    void foo()
    {
        A::foo();
        std::cout << "Do another thing." << std::endl;
    }
};
结构A { void foo() { std::cout在
B::foo()
中调用
A::foo()

struct A
{
    void foo()
    {
        std::cout << "Do one thing." << std::endl;
    }
};

struct B : public A
{
    void foo()
    {
        A::foo();
        std::cout << "Do another thing." << std::endl;
    }
};
结构A { void foo() { std::cout在
B::foo()
中调用
A::foo()

struct A
{
    void foo()
    {
        std::cout << "Do one thing." << std::endl;
    }
};

struct B : public A
{
    void foo()
    {
        A::foo();
        std::cout << "Do another thing." << std::endl;
    }
};
结构A { void foo() { 标准::cout