Typedef C++, couldn't resolve its meaning
I read this typedef line in a C++ book, but I couldn't resolve its meaning:
typedef Shape* (*CreateShapeCallBack开发者_Python百科)();
Now, CreateShapeCallBack stands for what, any idea? Thanks.
It's the type of a pointer to a function that returns a pointer to a Shape and takes no parameters. You could use it like this:
Shape * Func() {
// do stuff - return Shape pointer
}
...
CreateShapeCallBack p = Func;
Pointer to a function returning a pointer to a Shape
instance (which is Shape*
) and taking void
as a param - no params.
Compare this with, for example typedef int (*function_pointer)(double);
- this is a pointer to a function that takes double
as a parameter and returns int
...
It defines CreateCallBack as a function pointer. The function haves no arguments and returns the Shape pointer.
returntype (*functionpointer)(parameters, ...)
is a function pointer in c++
精彩评论