Finally finished making my way through Lesson 9 in Sam’s Teach Yourself C++ in One Hour a Day, 8th Edition
Some of the concepts I don’t fully understand just yet, but I’m hoping that StackOverflow may help with these.
For the remaining topics listed here, I’m going to try my best to explain them simply, in my own words.
Just as a variable is copied when it is passed as a parameter (by value) to a function, objects are copied, as well.
Problems may arise if this default copy behavior is allowed with objects. For instance, if you dynamically create a pointer in the constructor, when this object is copied the pointer is also copied. This means that you now have two pointers which point to the same address.
Continue reading “C++ – Classes and Objects, Part III”
Continuation of Lesson 9 in Sam’s Teach Yourself C++ in One Hour a Day, 8th Edition
A constructor is a special method that is run when an object is created. It lets the compiler know how the object will be built, or constructed. Constructors are useful for initializing member variables. You can also have multiple constructors, meaning they can be overloaded.
Continue reading “C++ – Classes and Objects, Part II”
What I’m learning from Lesson 9 in Sam’s Teach Yourself C++ in One Hour a Day, 8th Edition
Object-oriented programming (OOP) is a different way of thinking about programs. Typically, beginner programmers are introduced to procedural programming — code is organized into different functions. The code can usually be read from the top to bottom, and the flow can be recognized.
With OOP, as the name suggests, you are encouraged to think of your data as different objects. For example, think of a human. A human is an object that has attributes, such as first name, last name, height, weight, etc. This human object can also carry out methods, or do things, such as speak, jump, eat, sleep, etc.
With this way of thinking about programming, you can then organize your code into different objects, each describing a specific part of your program and executing the logic piece by piece.
Continue reading “C++ – Classes and Objects, Part I”
Markdown is a simple markup language (similar to HTML) that is used to format the README.md files in GitHub. Since I’m planning on using GitHub more, I wanted to learn the basics of Markdown.
In my very first post, Learning Git & GitHub, part of the process was creating a very simple, barebones Markdown file.
I’m going to add some more text to this file and format it using Markdown. Then, I will use my new GIT knowledge to update the README.md file in my GitHub repo.
I watched a very brief introduction to Markdown from Brad Traversy on YouTube.
Continue reading “Learning Markdown”
I learned about references at the end of Lesson 8 in Sam’s Teach Yourself C++ in One Hour a Day, 8th Edition.
References are essentially aliases. To use a reference, an ampersand (&) is used on the l-value after the type. When a reference is defined, it takes on the value of the variable assigned to it. As a result, both the reference and the original variable can be used interchangeably. The value can be update by changing either the original variable or the reference variable.
int x = 42;
int & intRef = x; // create reference to x
x = 30; // value of intRef is also 30
intRef = 19; // value of x is changed to 19, too
Continue reading “C++ – References”
Currently going through Sam’s Teach Yourself C++ in One Hour a Day, 8th Edition from Safari Books Online.
In Lesson 8 I learned a few more things about pointers.
Dynamic Memory Allocation
Arrays are an example of static memory allocation. A set block of memory is reserved when it is defined. You cannot add more memory blocks, if needed. Nor can you shrink the allocated memory if you do not need as much. This is where dynamic memory allocation comes in.
Continue reading “C++ – Pointers, Part II”
One of the aspects of C++ I remember struggling with a bit was pointers. So, I want to make sure and jot down some of the things I’m learning about them.
I referenced this website: http://www.cplusplus.com/doc/tutorial/pointers/
I may reference it again for other topics. I am going through another book on C++, and just reached the Pointers chapters, so I may have another post on this topic.
Here’s what I learned about pointers:
Essentially, the pointer is a variable that contains an address — it points to the address of another variable. From my understanding, pointers are useful since you can manipulate data simply by pointing to its address and dereferencing it, rather than having to pass the data itself onto the stack. Imagine having to pass a large value or an array onto the stack.
Continue reading “C++ – Pointers”