On Jun 9, 3:31 pm, Frank Birbacher <bloodymir.c...@gmx.net> wrote:
> James Kanze schrieb:
> >> The mem_fun will not do virtual dispatch here!
> > The mem_fun has exactly the same semantics of calling the
> > function directly;
> This is nothing a boost::bind could do, right? The mem_fun has
> extra help from the compiler here, right?
No extra help. It uses a pointer to member function.
> > if the function is declared virtual in Base, and you call it
> > correctly with a pointer to the base, then it will use
> > virtual dispatch.
> So, the following won't do the same?
> struct Base {
> virtual void foo() {}
> };
> struct Dev : Base {
> void foo() {}
> void test();
> };
> void Dev::test() {
> using boost::bind;
> this->Base::foo(); //calls Base::foo
> this->*(&Base::foo)(); //calls Base::foo ??
Doesn't compile.
(this->*(&Base::foo))() ;
calls Dev::foo.
> mem_fun(&Base::foo)(this); //calls Dev::foo ?? WTF?
Calls Dev::foo.
> bind(&Base::foo, this)(); //calls Base::foo ??
Calls Dev::foo.
> }
> I don't get it. How does mem_fun work?
It uses a pointer to member function.
--
James Kanze (GABI Software) email:
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
|