From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/CPLUSPLUS/CONCEPT/fundefault.html | 115 ++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 reference/CPLUSPLUS/CONCEPT/fundefault.html (limited to 'reference/CPLUSPLUS/CONCEPT/fundefault.html') diff --git a/reference/CPLUSPLUS/CONCEPT/fundefault.html b/reference/CPLUSPLUS/CONCEPT/fundefault.html new file mode 100644 index 0000000..80cd0aa --- /dev/null +++ b/reference/CPLUSPLUS/CONCEPT/fundefault.html @@ -0,0 +1,115 @@ + + +Default Parameters. + + + +
+

Default Parameters.

+
+

+Within C you could not provide default values for function +parameters. Well, C++ has come to your rescue. +

+ +

+ + + + +
+
+
+    #include <iostream.h>
+    
+    void Func( int one, int two=2, int three=3);
+    
+    main ()
+    {
+        Func(10, 20, 30);
+        Func(10, 20);   // Let the last parm default
+        Func(10);       // Just provide the required parm.
+    }
+    
+
+    void Func( int one, int two, int three)
+    {
+        cout << "One   = " << one   << endl;
+        cout << "Two   = " << two   << endl;
+        cout << "Three = " << three << endl << endl;
+    }
+
+
+
+ +

+From this example, you can see that the prototype/function declaration +gives default values for the second and third parameters. It is now +down to the programmer calling the function to decide how many +s/he wants to provide. +

+There are some basic rules that should be applied when using +default parameter values. +

+

+


+

Examples:

+ + +
+

See Also:

+ +o +Function Name Overloading. +
+
+ +

C References

+

+o +Function basics. + + + +


+

+

+ + + + +
+Top + +Master Index + +Keywords + +Functions +
+
+

+


+ +
Martin Leslie + +

+ + + -- cgit v1.2.3-54-g00ecf