again on function pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • enzo

    again on function pointer

    hi all,

    could anyone explain me why this doesn't compile??

    #include<iostre am>

    using namespace std;
    class test;

    class messenger
    {
    public:
    messenger(void( test::*p_f)() = 0)
    : m_f(p_f)
    {
    }

    void
    call()
    {
    (*this.*m_f)();
    }

    void
    set(void(test:: *p_f)())
    {
    m_f = p_f;
    }

    void (test::*m_f)();
    };

    class test
    {
    public:
    test()
    : m(0)
    {
    m.set(&test::f) ;
    }

    void f()
    {
    cout << "Hallo! " << endl;
    }

    messenger m;
    };


    int
    main()
    {
    test a;
    a.m.call();
    return 1;
    }

    thanks
    e
    ~
  • David Harmon

    #2
    Re: again on function pointer

    On 30 Jan 2004 01:55:24 -0800 in comp.lang.c++,
    principeoussama @yahoo.com (enzo) was alleged to have written:[color=blue]
    >could anyone explain me why this doesn't compile??[/color]

    No fair asking about code that doesn't compile without
    quoting the error message.
    [color=blue]
    >class messenger
    >{
    >public:[/color]
    ....[color=blue]
    > void
    > call()
    > {
    > (*this.*m_f)();
    > }[/color]
    ....[color=blue]
    > void (test::*m_f)();[/color]

    m_f points to a member function of class test.

    (*this) is an object of class messenger.

    You cannot call a test member function on a messenger object.

    Comment

    Working...