This page was written to help students to understand some of the advanced concepts of object orientated programming in C++. It does not start with the details of getting started in C++, or the basics of controlling program flow. Rather, it starts off with the advanced concepts of classes and objects, inheritance, polymorphism, arrays and pointers.
The advanced concepts are all demonstrated using working C++ programs. The programs have been heavily commented to give students a step by step explanation for every line of code and every new concept. The code has been formatted using an easy to follow colour scheme specially designed for C++ code listings.
Importantly, all of the programs have been released as free software under the GNU GPL.
A free C++ advanced concepts guide with free software programs:
The Free C++ Advanced Concepts GuideThis program demonstrates classes, objects, constructors, destructors and member functions in C++. Free software published under the GNU GPL:
This program demonstrates class inheritance, polymorphism and friend functions in C++. Free software published under the GNU GPL:
This program demonstrates passing arrays to functions by reference, passing pointers to arrays to functions and changing the contents of a memory address using a pointer. Free software published under the GNU GPL:
C++ Arrays and Pointers Demo (view code in browser)C++ (Stroustrup, AT&T Bell Labs, New Jersey, 1979) extended the C programming language by adding Simula 67-like features to it, creating a powerful object orientated programming language; it was originally named C with classes.
Fortran (Backus, IBM, New York, 1957), short for mathematical FORmula TRANslation, was the first widely used high-level computer language to use a compiler to produce machine code, making programming easier. Fortran was most popular during the 1950s and 1960s. It included the modern concept of data abstraction (information hiding). The floating point data type had it’s internal mechanism hidden from the programmer.
In 1967, Simula 67 (Nygaard & Dahl, Norwegian Computing Center, Oslo, 1967) was the world’s first object orientated programming (OOP) language. It used classes; data structures with data and functions packaged together.
Smalltalk (Kay, Ingalls & Goldberg, Xerox PARC, California, 1972) was a programming language designed so that objects could be communicated with by passing messages. The Smalltalk team were the first to introduce the term object orientated programming (OOP). Smalltalk was strongly influenced by Lisp (McCarthy, MIT AI Labs, Cambridge, Massachusetts, 1958), short for LISt Processor, which used lists of objects/ atoms.
The C programming language (Ritchie, AT&T Bell Labs, New Jersey, 1972) was written to re-write a portable version of the Unix operating system (originally written in assembly language) in C, a high-level computer language which uses a compiler to produce machine code. C++ (Stroustrup, AT&T Bell Labs, New Jersey, 1979) extended the C programming language by adding Simula 67-like features to it, creating a powerful object orientated programming language; it was originally named C with classes. C++ was first standardised by the ISO (International Organization for Standardization ) in 1998.
C++ programs can be written using a simple text editor:
All of the programs in this guide were written using the gedit text editor in Linux. This text editor has the advantage of recognising C++ code and formatting it in colour (syntax highlighting).
C++ files are saved with the file extension .cpp For example: ClassesAndObjects.cpp
A compiler converts the C++ program into executable machine code. The GNU C++ compiler is freely available from the Free Software Foundation:
https://gcc.gnu.org/The programs in this guide were compiled using the Code::Blocks IDE (integrated development environment). Code::Blocks is a free cross-platform IDE which runs on Linux, Mac and Windows.
http://www.codeblocks.org/MinGW (Minimalist GNU for Windows) is a free programming environment for Windows.
http://www.mingw.org/The Nanyang Technological University in Singapore have produced an excellent C++ introduction here:
https://www.ntu.edu.sg/home/ehchua/programming/cpp/cp0_Introduction.html