Re: avoiding virtual call with pointer to member function
xtrigger303@gmail.com wrote:
Hi to all,
a newbie question. Is it possible to avoid the virtual mechanism with
pointers to members syntax the same way it's done with an explicit
call ( obj.Base::Func() )? It would be useful for something I'm
doing... check out the trivial program down here...
Thanks in advance,
Francesco
#include <iostream>
struct Base
{
virtual ~Base() {}
virtual void Do() const { std::cout << "Base\n"; }
};
struct Der : public Base
{
virtual void Do() const { std::cout << "Der\n"; }
};
int main()
{
Der obj;
obj.Base::Do(); // avoid virtual call
void ( Base::*ptrToMembFunc )() const = &Base::Do;
( obj.*ptrToMembFunc )(); // virtual call
// is there a way to avoid virtual call with pointers to member
functions
// as in the above direct call?
}
You could try forcing 'obj' into being a 'Base' by means of
'static_cast'...
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask