Thread: typedef question.

  1. #1
    Registered User
    Join Date
    Jun 2008

    typedef question.

    I've read that you can use typedef to create a alias of a datatype, as example:
    typedef long miles; // define miles as an alias for long

    but then I saw this code:

    typedef QWidget * (*createModule_t)(QWidget *, const char *, const QXmlAttributes *);
    typedef void (*destroyModule_t)(QWidget *);

    what happens in these 2 lines?
    (QXmlAttributes and QWidget are classes)
    Last edited by mikalv; 06-23-2008 at 04:40 PM.

  2. #2

    Join Date
    Apr 2008
    The syntax for declaring typedefs is just like initializing objects.

    // Pointer to function returning int:
    int (*ptr)();
    // Alias of 'pointer to a function returning int':
    typedef int(*ptr_t)();
    So in your example, createModule_t is a datatype equivalent to a pointer to a function taking 3 parameters and returning a QWidget*.

    destoryModule_t is a datatype equivalent to a pointer to a function taking a QWidget* and returning void.

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    WNDPROC and THREAD_ENTRY_POINT are some good examples of this.
    I just want to use my computer in a productive manner, not learn how to use it. Elysia
    A year spent in artificial intelligence is enough to make one believe in God. Alan Jay Perlis

  4. #4
    Registered User
    Join Date
    Jun 2008
    so that's means that it's a way to make custom datatypes?

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Somewhat, though it is more like a way to give new names to existing types.
    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. Help with ZwQueryDirectoryFile for my Driver.
    By taDo in forum Windows Programming
    Replies: 9
    Last Post: 11-27-2008, 08:54 AM
  2. Error: redefinition of typedef xxxx
    By Rocha in forum C Programming
    Replies: 2
    Last Post: 11-24-2008, 09:19 AM
  3. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  4. Help...typedef struct...confusing...
    By darkchild in forum C Programming
    Replies: 1
    Last Post: 01-23-2007, 08:03 AM
  5. question about typedef
    By volk in forum C++ Programming
    Replies: 8
    Last Post: 05-30-2003, 10:53 PM