May 2017
Intermediate to advanced
590 pages
17h 18m
English
Before we see how std::invoke() works, let's have a short look at how different callable objects can be invoked. Given a function, obviously, the ubiquitous way of invoking it is directly passing it the necessary parameters. However, we can also invoke the function using function pointers. The trouble with function pointers is that defining the type of the pointer can be cumbersome. Using auto can simplify things (as shown in the following code), but in practice, you usually need to define the type of the pointer to function first and then define an object and initialize it with the correct function address. Here are several examples:
// direct call auto a1 = add(1, 2); // a1 = 3 // call through function pointer int(*fadd)(int ...Read now
Unlock full access