C++
From DocForge
C++ is a compiled, statically typed, multi-paradigm language. It was created by Bjarne Stroustrup as an add-on to C (originally only to the C preprocessor). Some popular compilers are g++ and Visual Studio.
Contents |
[edit] Characteristics
- Strongly typed variables
- Complex data types (struct, union and enum)
- Type casting
- Functions
- Object oriented programming (optional)
- Pointer referencing and dereferencing
- header-files and pre-compilation-macroes
[edit] Hello World
A simple Hello World program looks like this.
#include <iostream> using namespace std; int main() { cout << "Hello World!" << endl; return 0; }
[edit] Object Oriented Programming in C++
The creation of C++ was performed to add object oriented concepts to the already useful C language. As such C++ is considered a high-level language, although it retains the low-level facilities of C. The three major object oriented concepts of C++ are: encapsulation, inheritance, and polymorphism.
These three concepts take some getting used to, and once understood, they expose the underlying power of C++ for it's best and highest use.
Encapsulation is the best beginning for an explanation of the OO Concepts. The C++ language has classes. Classes are descriptions and implementations of data types, and the functions required to handle them. Many programming errors have been found that were the result of passing the wrong types of data to functions. C++ is a strongly typed language. Placing the data types and their functions together is a good way to keep thing straight. If you compile with all the warnings turned on, and warnings considered errors, once compiled, your program will probably do what it is written to do. Once you get used to using classes, you begin to see they are an elegant way of organizing your data and procedures and functions. Classes can be very simple and straightforward, or complex and time consuming to understand. If the goal of the programmer is to write understandable code, classes are a nice way to do that.
Inheritance in C++ has to do with the fact that classes can be new or derived from other existing classes, and the derived classes will benefit from the data and the functions of the base classes. This is not a simple topic, and it is the subject of many chapters in many books. Having the term defined is a start.
Polymorphism is even more difficult to get a clear idea of than inheritance. Polymorphism is the glue that binds frameworks together. Here is a simple explanation to give you the feel of it. If all objects are instances of classes derived from another class, and that other class provides a function, all objects will have that function. This is as simple as I can say it, but don't feel bad if it takes some time to sink in. This is the primary structure that allows for application frameworks to exist. In all fairness, it should be mentioned that SmallTalk predated C++ as an object oriented language, but C++ gained more popularity. This may be partially because Microsoft started selling a C++ compiler for Windows, and not a SmallTalk compiler.
[edit] Libraries
- Parallelism / Threading

