Let's consolidate the concepts of constructors and member methods Part 2

Let's consolidate the concepts of constructors and member methods Part 2

Lesson Details:
June 29, 2020

I: Introduction to Programming Languages

Programming languages are tools for describing computation. It is an abstract language, and it's design is to make the description of computation as easy as possible. Programming languages can be used to control computers or other machines such as robots.

The purpose of programming languages is to make it easier for humans to write computer programs.

Computer programs can also be used to control other machines such as robots.

Computer programs written in a programming language are called source code. Source code can be translated into a form that computers can understand (machine code) and then the computer can run the program.

Source code is written using syntax rules. These rules tell you how to write the code so it will work properly. Formal definition of syntax is not important here, but it is important to understand that programs must follow certain rules in order to be recognized as valid by a compiler or interpreter. The set of rules that define what is valid source code for a language is called the language's syntax.

When you execute a program, the computer follows its instructions one-by-one. A program is often referred to as the execution of a sequence of instructions. The steps that a computer carries out when executing a program is called the program's semantics. The meaning of the program's instructions is defined by its semantics.

The process of translating source code into something that can be executed by a computer is called compilation. This process involves translating the source code into an intermediate language which is then further compiled into machine language.

Programs are often run on computers connected to networks ranging from local area networks to the internet. Programs are normally stored on servers running special software called an operating system which makes sure that users can access each other's files and share information. Programmers often use Integrated Development Environments (IDE), which are programs for writing source code, debugging, testing, and compiling. These integrated environments include features such as intelligent code completion, code refactoring, task management, and revision control.

II: Body

A: Let's consolidate the concepts of constructors and member methods part 2

Constructor functions are functions that are called automatically when an object is created, before any method of that object is called. This is known as object construction or instantiation. Constructors have the same name as their corresponding classes, and do not have a return value - they have an optional parameter list but no return type. Constructors are usually declared with the keyword "constructor" in C++, although some languages (like Python) allow both constructor functions and regular functions to be called without any indication that they are constructors.

It may happen that you would like to call your constructor function in your main() function, thus causing it to execute before calling your main function. You can't do this in C++ because the C++ compiler requires every class to be initialized before it can be used (i.e., before any method of that class can be called). To overcome this limitation, you need to use the "this" keyword to initialize your class with data at runtime before calling your constructor function; this is known as delayed initialization. Below is an example of delayed initialization in action:

Course content