introduced new book
This commit is contained in:
@@ -36,11 +36,41 @@ int square(int x) {
|
||||
Function abstraction is the ability to make a function easy to use without understanding exactly how the function works line by line. This makes it easy for other people to use your code faster. It is a good practice to make your code easy to use for other people.
|
||||
|
||||
## Default arguments
|
||||
|
||||
--------------------
|
||||
Suppose you want a function to occassionaly not have values for parameters explicitly define, you can set a default value for your parameters within your function.
|
||||
|
||||
```c++
|
||||
void average(float num1 = 3, float num2 = 3, float num3 = 3);
|
||||
```
|
||||
|
||||
In this example, the default parameters were create in the function prototype. Suppose you call the function by `average();`, then without passing and values, num1, num2, and num3 were all initialized with 3 as we have define in the prototype. Default arguments also work with just one parameter. You can set whatever parameter you want to have a default argument. Also, as long as the default argument is defined in the prototype, you should not include it in the definition. __Keep in mind, default arguments must be at the end of the parameter list.__
|
||||
In this example, the default parameters were create in the function prototype. Suppose you call the function by `average();`, then without passing and values, num1, num2, and num3 were all initialized with 3 as we have define in the prototype. Default arguments also work with just one parameter. You can set whatever parameter you want to have a default argument. Also, as long as the default argument is defined in the prototype, you should not include it in the definition. __Keep in mind, default arguments must be at the end of the parameter list.__ Also __you cannot use default arguments with non-constant pass by reference types__.
|
||||
|
||||
## Function overloading
|
||||
-----------------------
|
||||
Function overloading lets you use functions with the same name but contain different parameters.
|
||||
|
||||
```c++
|
||||
void display(string message) {
|
||||
std::cout << message << '\n';
|
||||
}
|
||||
|
||||
void display(int data) {
|
||||
std::cout << data << '\n';
|
||||
}
|
||||
```
|
||||
|
||||
Having both of these definitions is an example of function overloading. The implementation of this is quite simple.
|
||||
|
||||
Rules for modifying function signatures:
|
||||
|
||||
1. # of parameters
|
||||
2. Parameter data types
|
||||
3. Pass by value / Pass by reference
|
||||
- __Does not change signature__
|
||||
4. Addition of const modifier
|
||||
- __Only changes signature when using Pass-by-reference__
|
||||
5. Introducing default arguments
|
||||
- __Does not change signature_
|
||||
6. Modifying return types
|
||||
|
||||
|
||||
|
||||
9
content/gametheory/frontcover.md
Normal file
9
content/gametheory/frontcover.md
Normal file
@@ -0,0 +1,9 @@
|
||||
+++
|
||||
date = '2026-03-05T18:36:18-06:00'
|
||||
draft = false
|
||||
title = 'Game Theory Notes'
|
||||
layout = 'frontcover'
|
||||
type = 'book'
|
||||
tags = 'gametheory'
|
||||
chapterno = 0
|
||||
+++
|
||||
Reference in New Issue
Block a user