CodeRef
CodeRef
  • Software
    • VSCode
  • Midjourney_AI
    • Midjourney Cheat Sheet
  • aws
    • S3 Reference
    • Services
  • bash
    • .bashrc File Contents
    • CAN
    • _System Config File Locations
    • argument-length-limits
    • Conditionals
    • Data Structures
    • File Permissions
    • File Syncing
    • File System
    • Functions
    • General
    • Loops
    • My Functions
    • Networking
    • Number Operations
    • OpenVPN
    • Operators
    • Resource Management
    • Serial RS232
    • Spinning Wheel Animation
    • SSH
    • Text Operations
    • Environment Variables
  • cpp
    • ChatGPT | Pointers vs. References
    • arrays
    • Classes
    • Data Types / Structures
    • Enumerated Classes
    • Exception Handling
    • Function Objects
    • Functions
    • I/O
    • Loops
    • Macros
    • Namespaces
    • New Features
    • Pointers
    • Scope
    • Smart Pointers
    • Raw String Literals
    • Style Guide
    • Switch Case
    • Templating
    • How to Use tinyxml2
    • Useful Libraries
    • google-test
    • Conditionals
    • Rule of Three/Five
    • Optional Parameters
    • Keywords
    • Filesystem
    • Random
    • Casting
    • tools
  • git
    • Code Review Dependency Strategy
    • Git Bisect Guide
    • Git Reference
    • removing-cherry-picks
    • Useful Tools
    • Graphite Reference
  • js
    • functions
    • Javascript Reference
  • linux
    • Display
    • Dual Boot with Windows
    • File System
    • NVIDIA
    • Sending/Receiving TCP/UDP Messages in Ubuntu
    • dynamically_linked_binaries
  • markdown
    • Images
    • obsidian-reference
  • python
    • Classes
    • Exceptions
    • Functions
    • Operations
    • Python Reference
    • unittest_command-line-args
    • unittest_magicmock_GPT
    • unittest_mock
    • unittest_printing
    • unittest_subtest
    • useful-stuff
    • jupyter
    • poetry
  • ros
    • _ROS Cheat Sheet
    • Create New Workspace
    • Install ROS
    • Node Sample - Listener
    • Node Sample - Talker
    • Node Template
    • Setup
    • urdf
  • excel
    • excel-reference
  • windows
    • File System
    • WSL - Windows Subsystem for Linux
    • WSL
  • software_engineering
    • uncle_bob_lectures
      • Overview
      • Lesson 01 - Notes
  • web
    • Front End
    • Hugo
    • new_frontend_tools
  • sql
    • cheatsheet
Powered by GitBook
On this page
  • Default Parameters
  • Function Overloading (Polymorphism)
  1. cpp

Functions

Default Parameters

In a function with default parameters, the arguments are optional.

void myfunction(int a=5, int b=1) {
}

You can mix required and optional arguments, but the optional ones must come after the required ones.

void myfunction(int a, int b=1) {
}

Function Overloading (Polymorphism)

// The function that matches the # arguments, and data types of
// the arguments provided, is the one that's called.
int myfunction(int a=5, int b=1) {
	return a+b;
}
double myfunction(double a=5.1, double b=4.4) {
	return a+b;
}

Passing Pointers

void increment(int &number) {
}

Constant Member Functions of a Class:

From Codeium:

Const Member Function:

  • A const member function is a member function that is declared with the const keyword at the end of the function signature.

  • It promises not to modify the state of the object on which it is called.

  • Inside a const member function, you cannot modify non-mutable data members, call non-const member functions, or modify the object itself.

  • It is a good practice to mark member functions as const if they do not modify the object's state.

Correct, the const keyword at the end of a member function declaration has no direct impact on whether the arguments passed to the function are modified.

The const keyword at the end of a member function declaration specifically relates to the object on which the member function is called. It indicates that the member function does not modify the state of the object itself.

Last updated 1 year ago