January 2020
Intermediate to advanced
454 pages
11h 25m
English
In the preceding example, you might have noticed that, when we used our custom header-only library, we included the library first. This is an essential first step to writing a header-only library. When writing examples or tests for header-only libraries, our library should be the first thing we include to ensure that all of the header's dependencies are defined in the header-only library and not in our example or test.
For example, suppose we change our library as follows:
#ifndef MY_LIBRARY#define MY_LIBRARYnamespace library_name{ void my_api() { std::cout << "The answer is: 42" << '\n'; }}#endif
As shown in the preceding code snippet, instead of returning an integer our API now outputs to stdout. We can use our new ...