[英]C++ Using base function in overridden function
I want to define a Interface which already implements some of the basic functions, which may have to be modified a little bite when they're overridden. 我想定义一个已经实现了一些基本功能的接口,当它们被覆盖时可能需要稍作修改。
Is it possible to call the base function inside of the overriding function in C++? 是否可以在C ++中的覆盖函数内部调用基本函数?
Example: 例:
class A
{
public:
void function1 (int a)
{
do_something_with(a);
}
};
class B : public A
{
public:
void function1 (int a)
{
// call of base function
function1 (a);
// further processing
do_something_more_with(a);
}
};
Would this work or would it lead to an infinite recursion? 这项工作还是会导致无限递归? Is there any way to do something like that?
有什么办法可以做这样的事情吗?
由于类A中的function1(int a)
是公共的,因此您可以使用以下方法在类B中调用它:
A::function1(a);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.