Disclaimer: This article intends to be a primer so that you may gain insight in order to understand beginner OOP articles better (for example on wikipedia). In order to grasp more abstract concepts, suspend as much logic as you would when watching Star Trek. Message not sponsored by anyone I know. Some neurons dissipated during the writing of this.
Definition: A reference variable is a “reference” to another variable. Better definition: A reference variable is just another pointer variable which will take its own space in memory from here References are nothing but constant pointers in C++. A statement int &i = j; will be converted by the compiler to int *const i = &j . Again from here Usage: Declare a reference as such with the
Pre-requisite You know pointers are important so you’re reading this How is data stored? When you declare variables, they are assigned a location in the computer’s memory. This location/address is actually where the value of the variable is stored. Let’s see a small example. You might not understand the code right, now that’s ok. Just pay attention to the output of cout and how it
“Header files, or .h files, allow related function, method, and class declarations to be collected in one place.”. This is useful as you can group together specific functionality and then export and use it at another place/file to be used by another program. There are 2 file extensions that we deal with “.h” and “.cpp”. The header file will have a “.h” extension whereas, the corresponding functions,
This section could have been better. While not terrible, it misses alot in the hopes of not being too lengthy or verbose (my guess). So far cout has been used in order to print things referenced by variables, ints or strings to the console. The “cout” functionality has been provided by the iostream standard library. Files can also be read by what is known as
<sstream> let us store streamed data instead of just outputting it to cout. So we can read whole files. Input Stream with istringstream object: “Once an istringstream object has been created, parts of the string can be streamed and stored using the “extraction operator”: >>. The extraction operator will read until whitespace is reached or until the stream fail” Streaming int The istringstream can stream
A function may contain 1 or more statements of code. When a function is called, the statements of code within a function block are executed. Syntax: When a function need not return anything, we use the “void” return type: Example: This is a simple function called printString that takes in 2 parameters of the string data type and prints them out. The function printString is