Introduction

Welcome to C++ For Dummies, 6th Edition. Think of this book as C++: Reader's Digest Edition, bringing you everything you need to know to start programming without all the boring stuff.

What's in This Book

C++ For Dummies is an introduction to the C++ language. I start from the beginning (where else?) and work my way from early concepts through more sophisticated techniques. I don't assume that you have any prior knowledge (at least, not of programming).

The book is rife with examples. Every concept is documented in numerous snippets and several complete programs.

Unlike other C++ programming books, C++ For Dummies considers the "why" just as important as the "how." The features of C++ are like pieces of a jigsaw puzzle. Rather than just present the features, I think it's important that you understand how they fit together. You can also use the book as a reference: If you want to understand what's going on with all the template stuff, for example, just flip to Chapter 25. Each chapter contains necessary references to other earlier chapters in case you don't read the chapters in sequence.

C++ For Dummies is not operating system–specific. It is just as useful to Unix or Linux programmers as it is to Windows-based developers. The book doesn't cover Windows or .NET programming.

You have to master a powerful programming language, like C++, first even if your plan is to become an accomplished Windows application or .NET programmer. Once you've finished C++ for Dummies you will be in position to continue in your area of specialization, whatever it might be.

What's on the CD

The CD-ROM included with C++ For Dummies contains the source code for the examples in this book. This can spare you considerable typing.

Your computer can't execute these or any other C++ programs directly. You have to run your C++ programs through a C++ development environment, which spits out an executable program. (Don't worry, this procedure is explained in Chapter 1.)

The programs in C++ For Dummies are compatible with any environment that implements the latest C++ standard from the International Standards Organization (ISO) as of this writing, the C++ 2009 standard. Since not every C++ compiler implements the complete 2009 standard, a full-featured C++ environment known as Code::Blocks using the GNU gcc compiler is contained on the enclosed CD-ROM.

The version of gcc (combined with Code::Blocks) on the disk is for any version of Windows 2000, XP, and Vista. Versions of gcc for Ubuntu and Debian Linux and for Macintosh OS X (Version 10.4 and later) can be downloaded at http://www.gnu.org. Make sure you download gcc Version 4.4 or later to maximize compatibility with the programs in the book.

What Is C++?

C++ is an object-oriented, low-level standard programming language. As a low-level language similar to and compatible with its predecessor C, C++ can generate very efficient, very fast programs. It is often used to write games, graphics software, hardware control software, and other applications where performance really counts.

As an object-oriented language, C++ has the power and extensibility to write large-scale programs. C++ is one of the most popular programming languages for all types of programs. Most of the programs you use on your PC every day are written in C++ (or the subset, which is the C language).

C++ has been certified as a 99.9 percent pure standard, which makes it a portable language. A standard C++ compiler exists for every major operating system. Some versions support extensions to the basic language — in particular, Visual C++ Express and Visual C++ .NET from Microsoft implement several extensions that allow their programs to interface better with other .NET languages. Nevertheless, any student is better off learning the standard C++ first. Learning the extensions is easy once you've master the basics demonstrated here.

Conventions Used in This Book

When I describe a message that you see onscreen, it appears like this:

Hi mom!

In addition, code listings appear as follows:

// some program
int main()
{
    ...
}

If you're entering these programs by hand, you must enter the text exactly as shown with one exception: The amount of whitespace (spaces, tabs and newlines) is not critical. You can't put a space in the middle of a keyword, but you don't have to worry about entering one too many or too few spaces.

C++ words are usually based on English words with similar meanings. This can make reading a sentence containing both English and C++ difficult to make out without a little assistance. To help out, C++ commands and function names appear in a different font, like this. In addition, function names are always followed by open and closed parentheses, such as myFavoriteFunction(). The arguments to the function are left off except when there's a specific need to make them easier to read.

Sometimes, I'll tell you to use menu commands, such as File

Conventions Used in This Book

Use of gender is always a tricky subject when writing a how-to book. I don't want to appear to be telling gentlemen how ignorant they are while giving the ladies a pass by using he and him all the time. In this book, I use the pronouns she and her when referring to the programmer and he and him when referring to the user of the program. So, she writes a program that he can use.

How This Book Is Organized

Each new feature is introduced by answering the following three questions:

  • What is this new feature?

  • Why was it introduced into the language?

  • How does it work?

Small pieces of code are sprinkled liberally throughout the chapters. Each demonstrates some newly introduced feature or highlights some brilliant point I'm making. These snippets may not be complete and certainly don't do anything meaningful. However, every concept is demonstrated in at least one functional program that you can execute and play with on your own computer.

And There's More

A real-world program can take up lots of pages. However, seeing such a program is an important didactic tool for any reader.

I use one simple example program that I call BUDGET. The program starts life as a simple, functionally oriented BUDGET1. This program maintains a set of simple checking and savings accounts. The reader is encouraged to review this program at the end of Part II. The subsequent version, BUDGET2, adds the object-oriented concepts presented in Part III. The examples work their way using more and more features of the language, culminating with BUDGET5, which you should review after you master all the chapters in the book. The BUDGET programs can be found on the book's CD-ROM. You can download a bonus chapter that describes these programs from www.stephendavis.com.

Part I: Introduction to C++ Programming

Part I starts you on your journey. You begin by examining what it means to write a computer program. From there, you step through the syntax of the language (the meaning of the C++ commands).

Part II: Becoming a Functional C++ Programmer

In Part II, you expand upon your newly gained knowledge of the basic commands of C++ by adding the capability to bundle sections of C++ code into modules and reusing these modules in programs. I also introduce that most dreaded of all topics, the C++ pointer. If you don't know what that means, don't worry — you'll find out soon enough.

Part III: Introduction to Classes

The plot thickens in Part III, which begins the discussion of object-oriented programming. Object-oriented (OO) programming is really the reason for the existence of C++. Take the OO features out of C++, and you're left with its predecessor language, C. I discuss things such as classes, constructors, destructors, and making nachos (I'm not kidding, by the way). Don't worry if you don't know what these concepts are (except for nachos — if you don't know what nachos are, we're in big trouble).

Part IV: Inheritance

Inheritance is where object-oriented programming really comes into its own. Understanding this most important concept is the key to effective C++ programming and the goal of Part IV. There's no going back now — after you've completed this part, you can call yourself an Object-Oriented Programmer, First Class.

Part V: Optional Features

By the time you get to Part V, you have the framework upon which to build. From now on it's a matter of expanding your knowledge of additional language features. Features such as file input/output, error-handling constructs, and templates are left to this part.

Part VI: The Part of Tens

What For Dummies book would be complete without The Part of Tens? Chapter 28 shows you the top ten best ways to avoid introducing bugs into your programs, bugs that you would otherwise have to ferret out on your own.

Chapter 29 takes you through some of the more esoteric features of C++ '09. The C++ 2009 standard is more than 1,300 pages of very small, terse writing. Fortunately, many of these features are meant for special subsets of the C++ community. You can safely put off understanding these features until you feel comfortable with the basics of the language.

Icons Used in This Book

Note

This is technical stuff that you can skip on the first reading.

Tip

Tips highlight a point that can save you a lot of time and effort.

Note

Remember this. It's important.

Warning

Remember this, too. This one can sneak up on you when you least expect it and generate one of those really hard-to-find bugs.

Note

This icon flag some 2009 additions to the language compared to the predecessor standard (which is known as C++ 2003). If you already have some familiarity with C++ and something seems completely new or if something doesn't work with your existing C++ tools, it may be because it's an '09 addition.

Where to Go from Here

Finding out about a programming language is not a spectator sport. I'll try to make it as painless as possible, but you have to power up the ol' PC and get down to some serious programming. Limber up the fingers, break the spine on the book so that it lies flat next to the keyboard (and so that you can't take it back to the bookstore), and dive in.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.154.252