我在寫一段簡單的代碼。如何從基類和派生類都調用函數?
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 ??
}
如何首先調用基類函數然後調用從派生的類??相同的功能。 我不想明確地調用每個函數,我只是調用派生類函數,並且應該自動調用基類函數。
我不想要任何構造函數來調用這些函數。
有沒有什麼辦法來實現這個或這是全部垃圾。
我修復了一些語法錯誤。請記住使用*工作*代碼的問題,否則在問題中的錯誤可能會隱藏你想問的問題。 –