Typedef C ++, could not solve its meaning

I read this typedef line in a C ++ book, but I could not solve its meaning:

typedef Shape* (*CreateShapeCallBack)();

Now, CreateShapeCallBack means, any idea? Thank.

+3
source share
4 answers

This is a type of function pointer that returns a pointer to a shape and does not accept any parameters. You can use it as follows:

Shape * Func() {
   // do stuff - return Shape pointer
}

...
CreateShapeCallBack p = Func;
+8
source

A pointer to a function that returns a pointer to an instance Shape(which is equal Shape*) and accepts voidas a parameter without parameters.

Compare this with, for example, typedef int (*function_pointer)(double);a pointer to a function that takes doubleas a parameter and returns int...

+2

CreateCallBack . .

+1
source
returntype (*functionpointer)(parameters, ...)

is a function pointer in C ++

+1
source

Source: https://habr.com/ru/post/1742246/


All Articles