| View previous topic :: View next topic |
| Author |
Message |
Raider Guest
|
Posted: Wed Sep 20, 2006 9:10 am Post subject: Calling base class virtual method |
|
|
I have class hierarchy with virtual methods like this:
class Base
{
public:
virtual void Show();
~Base();
};
class Derived : public Base
{
public:
virtual void Show();
void DoDerivedStuff();
~Base();
};
And I have a function dealing with Derived objects:
void foo(Derived& d)
{
d.DoDerivedStuff();
d.Show(); // <- but here I want to call Base::Show(),
// not Derived::Show()
// (or even DerivedDerived::Show())
}
What should I write to call Base::Show() in foo()?
Should I write special adaptor like this
void Derived::BaseShow()
{
Base::Show();
}
and call it? Or may be there is a simpler way? |
|
| Back to top |
|
 |
Ivan Vecerina Guest
|
Posted: Wed Sep 20, 2006 9:10 am Post subject: Re: Calling base class virtual method |
|
|
"Raider" <sraider (AT) yandex (DOT) ru> wrote in message
news:1158741166.883383.263580 (AT) m7g2000cwm (DOT) googlegroups.com...
:> What should I write to call Base::Show() in foo()?
:
: I tried pointer to member function:
: (d.*(&Base::Show))();
:
: But it calls Derived::Show()
Close - but you must avoid using a function pointer for it to work:
d.Base::Show(); // shall do
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com |
|
| Back to top |
|
 |
Raider Guest
|
Posted: Wed Sep 20, 2006 9:10 am Post subject: Re: Calling base class virtual method |
|
|
| Quote: | What should I write to call Base::Show() in foo()?
|
I tried pointer to member function:
(d.*(&Base::Show))();
But it calls Derived::Show()  |
|
| Back to top |
|
 |
|