C++ Programming/Programming Languages/C++
Contents |
[edit] Introducing C++
(pronounced "see plus plus") is a general-purpose, statically typed, free-form, multi-paradigm programming language supporting procedural programming, data abstraction, and generic programming. During the 1990s, C++ became one of the most popular computer programming languages.
[edit] Language history and standardization
Bjarne Stroustrup, a Computer Scientist from Bell Labs, was the designer and original implementer of C++ (originally named "C with Classes") during the 1980s as an enhancement to the C programming language. Enhancements started with the addition object-oriented concepts like classes, followed by, among many features, virtual functions, operator overloading, multiple inheritance, templates, and exception handling. These and other features are covered in detail along this book.
The C++ programming language is a standard recognized by the ANSI (The American National Standards Institute), BSI (The British Standards Institute), DIN (The German national standards organization), and several other national standards bodies, and was ratified in 1998 by the ISO (The International Standards Organization) as ISO/IEC 14882:1998, consists of two parts: the Core Language and the Standard Library; the latter includes the Standard Template Library and the Standard C Library (ANSI C 89).
Features introduced in C++ include declarations as statements, function-like casts, new/delete, bool, reference types, const, inline functions, default arguments, function overloading, namespaces, classes (including all class-related features such as inheritance, member functions, virtual functions, abstract classes, and constructors), operator overloading, templates, the :: operator, exception handling, run-time type identification, and more type checking in several cases. Comments starting with two slashes ("//") were originally part of BCPL, and were reintroduced in C++. Several features of C++ were later adopted by C, including const, inline, declarations in for loops, and C++-style comments (using the // symbol).
The current version, which is the 2003 version, ISO/IEC 14882:2003 redefines the standard language as a single item. The STL that pre-dated the standardization of C++ and was originally implemented in Ada is now an integral part of the standard and a requirement for a compliant implementation of the same. Many other C++ libraries exist which are not part of the Standard, such as Boost. Also, non-Standard libraries written in C can generally be used by C++ programs.
Since 2004, the standards committee (which includes Bjarne Stroustrup) has been busy working out the details of a new revision of the standard, temporarily titled C++0x, due for publication in the end of 2011. Some implementations already support some of the proposed alterations.
- C++ source code example
// 'Hello World!' program #include <iostream> int main() { std::cout << "Hello World!" << std::endl; return 0; }
Traditionally the first program people write in a new language is called "Hello World." because all it does is print the words Hello World. Hello World Explained (in the Examples Appendix) offers a detailed explanation of this code; the included source code is to give you an idea of a simple C++ program.
[edit] Overview
Before you begin your journey to understand how to write programs using C++, it is important to understand a few key concepts that you may encounter. These concepts are not unique to C++, but are helpful to understanding computer programming in general. Readers who have experience in another programming language may wish to skim through this section entirely.
There are many different kinds of programs in use today. From the operating system you use that makes sure everything works as it should, to the video games and music applications you use for fun, programs can fulfill many different purposes. What all programs (also called software or applications) have in common is that they all are made up of a sequence of instructions written in some form of programming language. These instructions tell a computer what to do, and generally how to do it. Programs can contain anything from instructions to solve math problems or send emails, to how to behave when a video game character is shot in a game. The computer will follow the instructions of a program one instruction at a time from start to finish.
[edit] Why learn C++ ?
Why not? This is the most clarifying approach to the decision to learn anything. Although learning is always good, selecting what you learn is more important as it is how you will prioritize tasks. Another side of this problem is that you will be investing some time in getting a new skill set. You must decide how this will benefit you. Check your objectives and compare similar projects or see what the programming market is in need of. In any case, the more programming languages you know, the better.
If you are approaching the learning process only to add another notch under your belt, that is, willing only to dedicate enough effort to understand its major quirks and learn something about its dark corners, then you would be best served in learning two other languages first. This will clarify what makes C++ special in its approach to programming problems. You should select one imperative and one object-oriented language. C will probably be the best choice for the former, as it has a good market value and a direct relation to C++, although a good substitute would be ASM. Java is a good choice for the other language, for similar reasons.
If you are willing to dedicate a more than passing interest in C++ then you can even learn it as your first language. Make sure to dedicate some time understanding the different paradigms and why C++ is a multi-paradigm, or hybrid, language.
Although learning C is not a requirement for understanding C++, you must know how to use an imperative language. C++ will not make it easy for you to understand and distinguish some of these deeper concepts, since in it you are free to implement solutions with a greater range of freedom. Understanding which options to choose will become the cornerstone of mastering the language.
You should not learn C++ if you are only interested in learning Object-oriented Programming, since the nomenclature used and some of the approaches taken to problems will make it more difficult to learn and master those concepts. If you are truly interested in Object-oriented programming, you should learn Smalltalk.
As with all languages, C++ has a specific scope of application where it can truly shine. C++ is harder to learn than C and Java but more powerful than both. C++ enables you to abstract from the little things you have to deal with in C or other lower level languages but will grant you more control and responsibility than Java. As it will not provide the default features you can obtain in similar higher level languages, you will have to search and examine several external implementations of those features and freely select those that best serve your purposes (or implement your own solution).