If we are using only one or two functions, this may not be a big problem. Now it becomes clear that every time we want to call one of the functions in gauss_sum.cpp in a different source file, we have to state the according declarations of these functions at the beginning of this source file.
#INPUT FILE FOR GAUSSSUM MANUAL#
Removing the Need of Manual Declaration ¶ Looking back at the Fibonacci Project ¶įirst, let us start by creating a new project. We will talk about this process in more detail in the next lessons. For larger projects with multiple programmers, this opens up the possibility to work in parallel on different parts of the code. Furthermore, we are able to change the implementation of a function without the user of this function recognizing it. So we can put the declaration of a function everywhere to make sure the code following is able to call the according function. Declarations are allowed to appear multiple times as long as they are providing the same interface. This is called the One Definition Rule (ODR). The definition of a function must appear exactly once in the project. For complex projects, this is not always possible.
So why are we even dealing with declarations? As we have seen in the second lecture, a call to a function that is only given by a definition has to appear after the respective definition. As a consequence, the definition is self-consistent and C++ does not need the declaration of the function. In C++, the definition of a function must include its interface because otherwise the function could not be properly implemented as the definition would not know about the types of input and output variables.