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