-
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)
-
The syntax for declaring typedefs is just like initializing objects.
Code:
// 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.
-
WNDPROC and THREAD_ENTRY_POINT are some good examples of this.
-
so that's means that it's a way to make custom datatypes?
-
Somewhat, though it is more like a way to give new names to existing types.