Thread: Pointer to member function

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Let's just put out correct code on calling member functions to avoid confusion...

    Code:
    class X
    {
    public:
        void foo();
    };
    
    typedef void (X::*X_foo_t)();
    
    int main()
    {
        X_foo_t bar = &X::foo;
        X x;
        (x.*bar)();
        return 0;
    }
    I think I may be half to blame for not entirely reading the thread correctly...
    Last edited by Elysia; 09-03-2011 at 11:29 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #2
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    Quote Originally Posted by Elysia View Post
    Let's just put out correct code on calling member functions to avoid confusion...

    Code:
    class X
    {
    public:
        void foo();
    };
    
    typedef void (X_foo_t)();
    
    int main()
    {
        X_foo_t* bar = X::foo;
        X x;
        (x.*bar)();
        return 0;
    }
    I think I may be half to blame for not entirely reading the thread correctly...
    First you correct manasij7479 for not using & to get the address of foo, and then you do the same thing yourself
    Code:
    typedef void (X::*X_foo_t)();
    X_foo_t bar = &X::foo;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Member Function Pointer...
    By yaya in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2009, 05:37 PM
  2. Pointer to member function?
    By C+/- in forum C++ Programming
    Replies: 9
    Last Post: 05-13-2007, 07:58 AM
  3. Pointer to member function
    By pheres in forum C++ Programming
    Replies: 3
    Last Post: 03-25-2007, 05:18 AM
  4. Replies: 3
    Last Post: 07-23-2006, 01:09 PM
  5. Pointer to a Member Function
    By TheDan in forum C++ Programming
    Replies: 25
    Last Post: 04-03-2006, 08:18 PM

Tags for this Thread