typedef

This is a discussion on typedef within the C++ Programming forums, part of the General Programming Boards category; Code: typedef CApaApplication*(* TApaApplicationFactory::TFunction)(); Can you tell me what is this? Is it a synonym for CApaApplication class? What does ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    164

    typedef

    Code:
    typedef CApaApplication*(* TApaApplicationFactory::TFunction)();
    Can you tell me what is this? Is it a synonym for CApaApplication class?

    What does the (*TApaApplicationFactory::TFunction)() mean? I don't understand the * operator before the TApaApplicationFactory class and () after TFunction.

    Can you simplify it?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    This defines TApaApplicationFactory::TFunction as a new type. It is a pointer to a function that returns a pointer to a CApaApplication object.

    (Using "old-style" "C *" thinking, then you're looking at (*TApaApplicationFactory::TFunction) must be a function (because of the ()) that returns a CApaApplication*; since dereferencing returns a function, the thing itself must be a pointer to a function.)

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,786
    It declares TFunction to be an alias of the type of a TApaApplicationFactory member function that takes no arguments and returns a pointer to CApaApplication.

    EDIT:
    Wait a minute... I recall that the * is after the class name, and checking with my compiler, it appears that the typedef example is invalid.

    EDIT #2:
    For a positive example of what I was talking about:
    Code:
    class X
    {
    public:
        void foo() {}
    };
    
    typedef void (X::*F)();
    
    int main()
    {
        F f = &X::foo;
        X x;
        (x.*f)();
    }
    Grr... I rarely work with member function pointers and had to take a few tries to get it right.
    Last edited by laserlight; 02-17-2009 at 05:57 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  3. 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
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 06:35 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