[
next
] [
prev
] [
prev-tail
] [
tail
] [
up
]
1.1.10.1
function pointer
A real example of function pointer is set_new_handler. It accepts a function pointer and return the same function pointer, so declaring such format is a little difficult.
void
failNew
(){
cerr
<<
"
Fail
␣
now
"
<<
endl
abort
();
}
-----------------------------------------
extern
void
(
*
set_new_handler
(
void
(
*
)()
)
)
();
//
This
function
declaration
is
very
complex
.
set_new_handler
(
failNew
);
A better method is to use typedef method.
typedef
void
(
*
FunPtr
)();
FunPtr
(
*
set_new_handler
)
(
FunPtr
);
set_new_handler
(
failNew
);
in C++ 11, When you want to function pointer, encourage you to use more lambda idiom. You also can use auto to store a lambda function for future use.
[
next
] [
prev
] [
prev-tail
] [
front
] [
up
]