Pointer to member typedef

This is a discussion on Pointer to member typedef within the C++ Programming forums, part of the General Programming Boards category; Consider this code: Code: class X { void foo() {} }; typedef void (X::*foo)(); void bar(foo n) {} int main() ...

  1. #1
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,311

    Pointer to member typedef

    Consider this code:
    Code:
    class X {
    	void foo() {}
    };
    
    typedef void (X::*foo)();
    
    void bar(foo n) {}
    
    int main() {}
    How in the world does the typedef bring foo into the global scope such that bar() can take an argument of type foo? What does the typedef really do here, and what really is the type of n as passed to bar()?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Correct me if I am wrong, but I believe what you have here are 2 different foo's in 2 different scopes. the first is the private member of X, the second is your typedef.

    Your typedef "foo" is "pointer to a member function of X, which returns a void and takes 0 arguments".

    X::foo() is still hidden from bar, and is unrelated to the typedef foo.
    Last edited by Bench82; 02-28-2006 at 07:57 AM.

  3. #3
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    Code:
    class X {
    public:
    		void foo() {cout<<(void*)this<<endl;}
    	};
    
    typedef void (X::*haha)();
    void bar(haha n) 
    {}
    
    int main() 
    {}
    haha has type void(__thiscall X::*)(void)
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #4
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    Code:
    void (X::*hop)() ;
    void *(X::foo)();
    Don't talk about bumping.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,311
    Thanks to Bench82 for the reply, I dont need any more help on this (which is why I didnt get back to the thread in the first place, but a thanks is in order nonetheless).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-22-2008, 12:07 PM
  2. file reading
    By gunghomiller in forum C++ Programming
    Replies: 9
    Last Post: 08-07-2007, 10:55 PM
  3. Pointer member not being recognised properly
    By drrngrvy in forum C++ Programming
    Replies: 9
    Last Post: 10-02-2006, 02:15 PM
  4. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 08:22 AM
  5. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 06:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21