Besides the basic rules, the following topics are discussed:
-
passing arguments
-
definition of inline functions
-
overloading functions and default arguments
-
the principle of recursion.
Significance Of Functions In C++
Elements of a C++ program
C++ supports efficient software development on the lines of the top-down principle. If you are looking to provide a solution for a more complex problem, it will help to divide the problem into smaller units. After identifying objects you will need to define classes that describe these objects. You can use available classes and functions to do so. In addition, you can make use of inheritance to create specialized classes without needing to change any existing classes.When implementing a class you must define the capacities of those objects, that is, the member functions, in your program. However, not every function is a member function.Functions can be defined globally, such as the function main() for example. Functions of this type do not belong to any particular class but normally represent algorithms of a more general nature, such as the search or sort functions of the standard library.Libraries
You will not need to program each "building block" yourself. Many useful global functions and classes are available from the C++ standard library. In addition, you can use other libraries for special purposes. Often a compiler package will offer commercial class libraries or graphical user interfaces. Thus, a C++ program will be made up of-
language elements of the C++ core
-
global functions and classes from the C++ standard library
-
functions and classes you have programmed yourself and other libraries.
Classes and functions that belong together are normally compounded to form separate source files, which can be compiled and tested independently. Using software components that you have already tested makes programming a complex solution much easier and improves the reliability of your programs. You can enhance the reusability of your source code by compiling your own libraries, but be sure to include comments for ease of readability.Compiled source files, also known as modules, are compounded by the linker to an executable file by reference to the libraries you include. If you modify a source file, you may also need to recompile other files. In large scale projects it is recommended to use the MAKE utility for module management. An integrated developer environment will offer the functionality of this utility when you create a new project. This includes your own source files, the libraries used, and the compiler/linker settings for program compilation. -
0 Comments