O'Reilly logo

C++ Primer, Fifth Edition by Barbara E. Moo, Josée Lajoie, Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

6.5.2. Inline and constexpr Functions

In § 6.3.2 (p. 224) we wrote a small function that returned a reference to the shorter of its two string parameters. The benefits of defining a function for such a small operation include the following:

• It is easier to read and understand a call to shorterString than it would be to read and understand the equivalent conditional expression.

• Using a function ensures uniform behavior. Each test is guaranteed to be done the same way.

• If we need to change the computation, it is easier to change the function than to find and change every occurrence of the equivalent expression.

• The function can be reused rather than rewritten for other applications.

There is, however, one potential drawback to making

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required