3.6. Definitions and UsesΒΆ

Pulling together all the code fragments from the previous section, the whole program looks like this:

This program contains three function definitions: new_line, three_line, and main.

Inside the definition of main, there is a statement that uses or calls three_line. Similarly, three_line calls new_line three times. Notice that the definition of each function appears above the place where it is used.

This is necessary in C++; the declaration or definition of a function must appear before (above) the first use of the function. It is possible for only the declarations for appear before a function is used and for the definition to appear later. These are called forward declarations.

Try This!

You should try compiling both programs with the functions in a different order and see what error messages you get.

Construct a block of code that correctly defines a the add_two function.


More to Explore

You have attempted of activities on this page