Static Polymorphism
Sign in

Static polymorphism

Function overloading allows programs to declare very multiple functions having the same name (but with different arguments). The functions are distinguished by the numeric number or types of the informal parameters. Thus, the same function name can refer to very different functions depending on the context in which it is used. The type returned by the function is not only used to distinguish overloaded functions or would result in a compile-time error message.

When declaring a function, a programmer can specify for one or much more parameters a default value. Doing so allows the parameters with defaults to optionally be omitted when the function is called, in which case the default arguments will be also used. When a function is called with fewer arguments than there are declared parameters, and explicit arguments are matched to parameters in left-to-right order, and with any unmatched parameters at the end of the parameter list being assigned their default arguments. In many cases, specifying default arguments in an only single function declaration is preferable to providing overloaded function definitions with different numbers of parameters.

Templates in C++programming language provide a sophisticated mechanism for writing generic, polymorphic code. In particular, through the Curiously Recurring Template Pattern, it's possible to implement a form of static polymorphism that closely mimics the syntax for overriding virtual functions. Since C++language templates are type-aware and Turing-complete, they can also be used to let the compiler resolve recursive conditionals and generate substantial programs through template Meta programming. Contrary to some opinion, and template code will not generate a bulk code after compilation with the proper compiler settings

related links: C, C++ Assignment Help

start_blog_img