Skip to content

CH01 Getting Started with C++

C++ = C + Classes + Templates

  • Its C ancestry brings to C++ the tradition of an efficient, compact, fast,and portable language.
  • Its object-oriented heritage brings C++ a fresh programming methodology, designed to cope with the escalating complexity of modern programming tasks.
  • Its template features bring yet another new programming methodology: generic programming.

1.1 Learning C++: What Lies Before You

C++ joins three separate programming categories:

  • the procedural language, represented by C;

  • the object-oriented language, represented by the class enhancements C++ adds to C;

  • the generic programming, supported by C++ templates.

1.2 The Origins of C++: A Little History

1.2.1 The C Language

~

1.2.2 C Programming Philosophy

  • Procedural Programming - Emphasizes Algorithms
  • Structured Programming
  • Top-Down Programming

1.2.3 The C++ Shift: Object-Oriented Programming

  • Object-Oriented Programming - Emphasizes Data
  • Bottom-Up Programming

1.2.4 C++ and Generic Programming

  • Generic Programming - Emphasizes Code Reuse, Independent of Specific Data Types

1.2.5 The Genesis of C++

OOP provides high-level abstractions, C provides low-level hardware access.

1.3 Portability and Standards

Portability: Write Once, Run Anywhere.

Two barriers to portability: - Machine Dependencies - Language Dependencies

1.3.1 Language Growth

~

1.3.2 This Book and C++ Standards

~

1.4 The Mechanics of Creating a Program

Programs are created in three steps: - Create the source code file. - Compile the source code file. - Link the compiled file.

1.4.1 Creating the Source Code File

IDE~

1.4.2 Compilation and Linking

Tip

When correcting errors, correct the first error first. If you cannot find the error on the line identified as having an error, look at the preceding line.

Summary

As computers have grown more powerful, computer programs have become larger and more complex. In response to these conditions, computer languages have evolved so that itโ€™s easier to manage the programming process.The C language incorporated features such as control structures and functions to better control the flow of a program and to enable a more structured, modular approach.To these tools C++ adds support for object-oriented programming and generic programming.This enables even more modularity and facilitates the creation of reusable code, which saves time and increases program reliability. The popularity of C++ has resulted in a large number of implementations for many computing platforms; the C++ ISO standards (C++98/03 and C++11) provide a basis for keeping these many implementations mutually compatible.The standards establishes the features the language should have, the behavior the language should display,and a standard library of functions, classes,and templates.The standards supports the goal of a portable language across different computing platforms and different implementations of the language. To create a C++ program, you create one or more source files containing the program as expressed in the C++ language.These are text files that must be compiled and linked to produce the machine-language files that constitute executable programs.These tasks are often accomplished in an IDE that provides a text editor for creating the source files,a compiler and a linker for producing executable files,and other resources, such as project management and debugging capabilities. But the same tasks can also be performed in a command-line environment by invoking the appropriate tools individually