Member Function Pointers - Typedef vs. Not

This is a discussion on Member Function Pointers - Typedef vs. Not within the C++ Programming forums, part of the General Programming Boards category; In my code I am going to use a typedef for the readability and whatnots, but I like knowing the ...

  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    Member Function Pointers - Typedef vs. Not

    In my code I am going to use a typedef for the readability and whatnots, but I like knowing the intricaces of what a type really is, and am wondering why one of these compiles and one does not.

    Code:
        blooz ( bleez::* r ) ( void ) const [ 4 ] =
        {
            &blaz::doo,
            &blaz::boo,
            &blaz::roo,
            &blaz::koo
        };
        
    
        typedef blooz ( bleez::*T ) ( void ) const;
        T t [ 4 ] =
        {
            &blaz::doo,
            &blaz::boo,
            &blaz::roo,
            &blaz::koo
        };
    The first one (non-typedef'd) gives me the errors:

    Code:
    Error	1	error C2090: function returns array
    
    Error	2	error C2440: 
        'initializing' : cannot convert from 
            'CPoint (__thiscall RotatingPong::CRotatingSquare::* )(void) const' to 
            'CPoint *(__thiscall RotatingPong::CRotatingSquare::* )(void) const'

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
        blooz ( bleez::* r ) ( void ) const [ 4 ] =
    Shouldn't the first one be more like this?
    Code:
        blooz ( bleez::* r [ 4 ] ) ( void ) const  =
    A minimal compilable example always helps me come up with a better answer.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Yeah, that's how it should be. I'll try to come up with some of them 'compilable examples' for the future. Many thanks.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  4. #4
    Registered User
    Join Date
    Dec 2006
    Posts
    30
    try
    Code:
        blooz ( bleez::* r [ 4 ] ) ( void ) const =
    ah, they beat me to it

  5. #5
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I do that stuff so often. I just leave like 20 windows open, and then remember I was going to reply to something, and then I do only to realize that someone had answered the question like an hour before me. If you watch me closely, you'll see that I delete quite a few posts (That or Ken does. Sorry Ken, my brain is sick).

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    > but I like knowing the intricaces of what a type really is
    I certainly agree for data, but function pointers are special for two reasons.

    1. The syntax for declaring them is pretty horrible, especially for more complex cases. Having to repeat that all over the place makes for hard to read and maintain code.

    2. There are only ever two things you can do with a function pointer - assign it, or call it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-19-2008, 12:06 AM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  4. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

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