1 *! |
1 /*! |
2 |
2 |
3 \page named-param Named Parameters |
3 \page named-param Named Parameters |
4 |
4 |
5 \section named-func-param Named "Function" Parameters |
5 \section named-func-param Named Function Parameters |
6 |
6 |
7 C++ makes it possible to use default parameter values when calling a |
7 C++ makes it possible to use default parameter values when calling a |
8 function. In such a case we do not have to give value for parameters, |
8 function. In such a case we do not have to give value for parameters, |
9 the program will use the default ones. Unfortunately sometimes this |
9 the program will use the default ones. Unfortunately sometimes this |
10 is not enough. If we do not want to give values for all the |
10 is not enough. If we do not want to give values for all the |
40 \endcode |
40 \endcode |
41 |
41 |
42 |
42 |
43 The usage is the following. |
43 The usage is the following. |
44 |
44 |
45 We have to define a class, let's call it named_fn. Let us assume that |
45 We have to define a class, let's call it \c named_fn. Let us assume that |
46 we would like to use a parameter, called X. In the named_fn class we |
46 we would like to use a parameter, called \c X. In the \c named_fn class we |
47 have to define an _X attribute, and a function X. The function |
47 have to define an \c _X attribute, and a function \c X. The function |
48 expects a parameter with the type of _X, and sets the value of |
48 expects a parameter with the type of \c _X, and sets the value of |
49 _X. After setting the value the function returns the class itself. The |
49 \c _X. After setting the value the function returns the class itself. The |
50 class also have to have a function, called for example run(), we have |
50 class also have to have a function, called for example <tt>run()</tt>, we have |
51 to implement here the original function itself. The constructor of the |
51 to implement here the original function itself. The constructor of the |
52 class have to give all the attributes like _X the default values of |
52 class have to give all the attributes like \c _X the default values of |
53 them. |
53 them. |
54 |
54 |
55 If we instantiate this class, the default values will be set for the |
55 If we instantiate this class, the default values will be set for the |
56 attributes (originally the parameters), initially. If we call function |
56 attributes (originally the parameters), initially. If we call function |
57 X, we get a class with the modified parameter value of |
57 \c X, we get a class with the modified parameter value of |
58 X. Therefore we can modify any parameter-value, independent from the |
58 \c X. Therefore we can modify any parameter-value, independent from the |
59 order. To run the algorithm we have to call the run() function at the |
59 order. To run the algorithm we have to call the <tt>run()</tt> function at the |
60 end of the row. |
60 end of the row. |
61 |
61 |
62 Example: named_fn().id(3).val(2).run(); |
62 Example: |
|
63 \code |
|
64 named_fn().id(3).val(2).run(); |
|
65 \endcode |
63 |
66 |
64 \section traits-classes Traits Classes |
67 \section traits-classes Traits Classes |
65 |
68 |
66 The procedure above can also be applied when defining classes. In this |
69 The procedure above can also be applied when defining classes. In this |
67 case the type of the attributes can be changed. Initially we have to |
70 case the type of the attributes can be changed. Initially we have to |
90 \endcode |
93 \endcode |
91 |
94 |
92 The result will be an instantiated Dijkstra class, in which the |
95 The result will be an instantiated Dijkstra class, in which the |
93 DistMap and the PredMap is modified. |
96 DistMap and the PredMap is modified. |
94 |
97 |
95 \section named-templ-func-param Named "Function" Template Parameters |
98 \section named-templ-func-param Named Function Template Parameters |
96 |
99 |
97 If the class has so called wizard functions, the new class with the |
100 If the class has so called wizard functions, the new class with the |
98 modified tpye of attributes can be returned by the appropriate wizard |
101 modified tpye of attributes can be returned by the appropriate wizard |
99 function. The usage of these wizard functions is the following: |
102 function. The usage of these wizard functions is the following: |
100 |
103 |