C++ In a Nutshell: A Desktop Quick Reference (In a Nutshell (O'Reilly))
|
| List Price: | £30.99 |
| Price: | £23.49 & eligible for FREE Super Saver Delivery on orders over £5. Details |
Availability: Usually dispatched within 24 hours
Dispatched from and sold by Amazon.co.uk
35 new or used available from £17.41
Average customer review:Product Description
C++ is a powerful, highly flexible, and adaptable programming language that allows software engineers to organize and process information quickly and effectively. This is a complete reference to C++ which is organized first by topic, then followed by an alphabetical reference to the language's keywords, complete with syntax summaries and pointers to the topic references. The library reference is organized by header file, and each library chapter and class declaration presents the classes and types in alphabetical order, for easy lookup. Cross-references link related methods, classes, and other key features. This resource should be useful for students as well as professional programmers. When you're programming, you need answers to questions about language syntax or parameters required by library routines quickly. What, for example, is the C++ syntax to define an alias for a namespace? Just how do you create and use an iterator to work with the contents of a standard library container? This book is a concise desktop reference that answers these questions, putting the full power of this flexible, adaptable (but somewhat difficult to master) language at every C++ programmer's fingertips.
Product Details
- Amazon Sales Rank: #179764 in Books
- Published on: 2003-05-08
- Original language: English
- Number of items: 1
- Binding: Paperback
- 704 pages
Editorial Reviews
About the Author
Ray Lischner began his career as a software developer, but dropped out of the corporate rat race to become an author. He started using C++ in the late 1980s, working at a company that was rewriting its entire product line in C++. Over the years, he has witnessed the evolution of C++ from cfront to native compilers to integrated development environments to visual, component-based tools. Ray has taught C++ at Oregon State University. He is the author of Delphi in a Nutshell and O'Reilly's upcoming C++ in a Nutshell, as well as other books.
Excerpted from C++ in a Nutshell by Ray Lischner. Copyright © 2003. Reprinted by permission. All rights reserved.
Chapter 4 – Statements
Statements define and control what a program does. This chapter describes the syntax and rules for C++ statements: expressions, loops, selection, and control. The statement syntax rules apply recursively, and wherever a statement is called for, you can use (almost) any of the statements in this chapter.
The syntax descriptions in this chapter are informal. See Chapter 12 for a precise BNF grammar.
Expression Statements
An expression statement computes an expression, such as a function call or assignment. The expression result is discarded, so the expression is typically evaluated for its side effects. (See Chapter 3 for details about expressions.) The statement syntax is simply an optional expression followed by a semicolon:
expr ;
or:
;
A statement with no expression is called a null statement. Null statements are most often used for loops when no code is needed in the loop body.
Here are several examples of expression statements:
42; // Valid but pointless
cout << 42; // More typical
x = y * z; // Remember that assignment is an expression
; // Null statementDeclarations
A declaration can appear anywhere a statement appears, and certain statements permit additional declarations within those statements.
Declarations made in a substatement (of a selection or loop statement) are limited in scope to the substatement, even if the substatement is not a compound statement. For example, the following statement:
while ( test( ) )
int x = init( );
is equivalent to:
while ( test( ) ) {
int x = init( );
}
The first example uses a declaration as the entire loop body, and the second uses a compound statement (enclosing the loop body in curly braces). In both cases, though, the scope of x is limited to the body of the while loop.
Declaration Statements
A simple declaration can appear wherever a statement can be used. You can declare an object, a type, or a namespace alias. You can also write a using declaration or using directive. You can declare a function, but not define a function, although there is rarely any reason to declare a function locally. You cannot define a namespace or declare a template.
In traditional C programming, declarations appear at the start of each block or compound statement. In C++ (and in the C99 standard), declarations can appear anywhere a statement can, which means you can declare variables close to where they are used. Example 4-1 shows examples of how declarations can be mixed with statements.
Customer Reviews
Nutshell Series
Like the other books (I have looked at) in the 'In a Nutshell' series this book provides a clear introduction into the language in question, then provides a clear and concise referance section.
Having said that it provides a clear introduction I don't think this book is for beginners, rather it is for a programmer who wants to learn another language, or for a C++ programmer would would like a referance book.
I brought it, am happy with it, and I doubt I could find better.
A concise and clear reference. Not an introduction
This book is concise, readable, and useful. As it makes clear on the cover, this is a reference book, and dives straight into very intense details of the syntax of C++. It is meant as the kind of book you can check when code that you thought should work isn't compiling, or when you want to know the proper way to write something particular. In fact, it reads quite like a plain-English version of the C++ standard itself.
It is perhaps surprising that the order of the chapters matches the abstraction level of each topic; starting with the parsing of characters in a source file, and working up through simple expressions to functions, classes, and finally to the standard libraries provided to assist you in common tasks. This may not be the order that the reader becomes interested in the topics, but it reflects the nature of this book as a reference rather than a cover-to-cover gripping read.
Even that first chapter contains treasures, such as the importance of spaces in nested template declarations, where ">>" would be parsed incorrectly. As well as statements of fact about the language, it includes a few human touches like using words that most of us recognise ("source file", when the standard says "translation unit"), and even advice not to use trigraphs; an obsolete part of the language which is still valid. Later, it warns about the safety of iterators, which can become almost as invalid as pointers, but doesn't spend long on stylistic advice, a bit more of which might be welcome. It dwells more on templates and containers, perhaps because they are less familiar to many readers.
There are lots of short examples of code, particularly in explaining how certain keywords are used and misused. There are cases where something might look like a type or a function; cases where a complicated pointer might be confusing about what it addresses, as well as more familiar cases about the scope of variables that might hide others of the same name. Again, these examples tend to be extremely short and to the point. There are a number of other examples of complete programs, covering a couple of pages, which have several classes with real functionality.
There are a decent number of cross references to other chapters, and some of the same information is repeated in several places; for example the "language reference" (chapter 12) lists every reserved word, with a half page description of its purpose, and refers to related sections that cover the topic in more detail. There were still occasions when it took me longer to find the page I wanted, than I had hoped. Perhaps the style of the index and referencing will become more familiar with use.
Seeing everything together, I was struck by how many innovative features are in the language, and most of them good. While Perl, Python, Java and the other languages we are familiar with have their own strengths (consider, for example, how Perl goes out of its way to let you write the same behaviour in many ways), and admitting that not everything in C++ is good (some people don't use exceptions for fear of ambiguity over resource ownership and clean-up), it was really inspiring to see what C++ has: multiple inheritance, virtual functions, exceptions, templates, dynamic casting, operator overloading, the standard library, namespaces, and so on.
By far the largest part of the book is the standard library reference, which is a good thing. The author is obviously pleased with this, and devotes more than half of the pages to explaining each function. Languages live or die by the capabilities (and elegance) of what comes "in the box". Edinburgh University's ML was an interesting-ish thing to study, but didn't help much when you wanted to interact with the real world. PHP is a cute language for web designers who think they can program, but its library is shockingly haphazard and incomplete. The C++ standard library is remarkable in its wealth of templates for storing data. Containers, iterators, maps, vectors, and the various other methods are covered with delight, encouraging you to get on with programming your new algorithms, instead of reimplementing Donald Knuth's. It also includes all of the C standard library, and various new methods, too.
In summary, this book is a good volume to have on the shelf for those occasions when your C++ compiler answers back about your syntax for subtle language features, and good to have on your desk when you want to use the standard library. Personally, I would have liked a bit more advice about what is efficient, or what is risky. It is very clearly and concisely written, which is a great benefit. Overall, a marked success.



