我在写一段简单的代码。如何从基类和派生类都调用函数?
class A
{
public:
virtual func()
{ // allocate memory
}
};
class B : public A
{
public:
func()
{ // some piece of code
// but call base class same function Ist
}
}
main()
{
A *ptr = new B;
ptr->func() //here I want to call base class function first
//and then derived class function
// How to implement ??
}
如何首先调用基类函数然后调用从派生的类??相同的功能。 我不想明确地调用每个函数,我只是调用派生类函数,并且应该自动调用基类函数。
我不想要任何构造函数来调用这些函数。
有没有什么办法来实现这个或这是全部垃圾。
我修复了一些语法错误。请记住使用*工作*代码的问题,否则在问题中的错误可能会隐藏你想问的问题。 –