Some Things to Try. McGraw-Hill The Complete Reference Fourth Edition
Oglas
Oglas
C h a p t e r 4 0 : P a r s i n g E x p r e s s i o n s
997
Answer is: 3
Enter expression: a/b
Answer is: 3
Enter expression: .
As you can see, the floating-point parser uses floating-point values, and the integer parser uses integer values.
Some Things to Try
As mentioned early on in this chapter, only minimal error checking is performed by the parser. You might want to add detailed error reporting. For example, you could highlight the point in the expression at which an error was detected. This would allow the user to find and correct a syntax error.
As the parser now stands it can evaluate only numeric expressions. However, with a few additions, it is possible to enable the parser to evaluate other types of expressions, such as strings, spatial coordinates, or complex numbers. For example, to allow the parser to evaluate string objects, you must make the following changes:
1. Define a new token type called STRING.
2. Enhance get_token( ) so that it recognizes strings.
3. Add a new case inside atom( ) that handles STRING type tokens.
After implementing these steps, the parser could handle string expressions like these: a = "one" b = "two" c = a + b
The result in c should be the concatenation of a and b, or "onetwo".
Here is one good application for the parser: create a simple, pop-up mini-calculator that accepts an expression entered by the user and then displays the result. This would make an excellent addition to nearly any commercial application. If you are programming for
Windows, this would be especially easy to do.
This page intentionally left blank
Appendix A
The .NET Managed
Extensions to C++
999
Copyright © 2003 by The McGraw-Hill Companies. Click here for terms of use.
1000
C + + : T h e C o m p l e t e R e f e r e n c e
M icrosoft’s .NET Framework defines an environment that supports the development and execution of highly-distributed, component-based applications.
It enables differing computer languages to work together, and provides for security, program portability, and a common programming model for the Windows platform. Although the .NET Framework is a relatively recent addition to computing, it is an environment in which many C++ programmers will likely be working in the near future.
Microsoft’s .NET Framework provides a managed environment that oversees program execution. A program targeted for the .NET Framework is not compiled into executable object code. Rather, it is compiled into Microsoft Intermediate Language
(MSIL), which is then executed under the control of the Common Language Runtime
(CLR). Managed execution is the mechanism that supports the key advantages offered by the .NET Framework.
To take advantage of .NET managed execution, it is necessary for a C++ program to use a set of nonstandard, extended keywords and preprocessor directives that have been defined by Microsoft. It is important to understand that these extensions are not defined by ANSI/ISO standard C++. Thus, code in which they are used is nonportable to other environments.
It is far beyond the scope of this book to describe the .NET Framework, or the C++ programming techniques necessary to utilize it. (A thorough explanation of the .NET
Framework and how to create C++ code for it would easily fill a large book!) However, a brief synopsis of the .NET managed extensions to C++ is given here for the benefit of those programmers working in the .NET environment. A basic understanding of the
.NET Framework is assumed.
The .NET Keyword Extensions
To support the .NET managed execution environment, Microsoft adds the following keywords to the C++ language:
_ _abstract
_ _event
_ _identifier
_ _pin
_ _try_cast
_ _box
_ _finally
_ _interface
_ _property
_ _typeof
_ _delegate
_ _gc
_ _nogc
_ _sealed
_ _value
Each of these is briefly described in the following sections.
_ _abstract
_ _abstract
is used in conjunction with _ _gc to specify an abstract managed class.
No object of an _ _abstract class can be created. A class specified as _ _abstract is not required to contain pure virtual functions.
A p p e n d i x A : T h e . N E T M a n a g e d E x t e n s i o n s t o C + +
1001
_ _box
_ _box
wraps a value within an object. Boxing enables a value type to be used by code that requires an object derived from System::Object, which is the base class of all .NET
objects.
_ _delegate
_ _delegate
specifies a delegate, which encapsulates a pointer to a function within a managed class (that is, a class modified by _ _gc).
_ _event
_ _event
specifies a function that represents an event. Only the prototype for the function is specified.
_ _finally
_ _finally
is an addition to the standard C++ exception handling mechanism. It is used to specify a block of code that will execute when a try/catch block is left. It does not matter what conditions cause the try/catch block to terminate. In all cases, the _ _finally block will be executed.
_ _gc
_ _gc
specifies a managed class. Here, “gc” stands for “garbage collection” and indicates that objects of the class are automatically garbage collected when they are no longer needed. An object is no longer needed when no references to the object exist. Objects of a _ _gc class must be created using new. Arrays, pointers, and interfaces can also be specified as _ _gc.
_ _identifier
_ _identifier
allows a C++ keyword to be used as an identifier. This is a special-purpose extension that will not be used by most programs.
_ _interface
_ _interface
specifies a class that will act as an interface. In an interface, no function can include a body. All functions in an interface are implicitly pure virtual functions. Thus, an interface is essentially an abstract class in which no function has an implementation.
_ _nogc
_ _nogc
specifies a nonmanaged class. Since this is the type of class created by default, the _ _nogc keyword is not usually used.
1002
C + + : T h e C o m p l e t e R e f e r e n c e
_ _pin
_ _pin
is used to specify a pointer that fixes the location in memory of the object to which it points. Thus, an object that is “pinned” will not be moved in memory by the garbage collector. As a result, garbage collection does not invalidate a pointer modified by _ _pin.
_ _property
_ _property
specifies a property, which is a member function that gets or sets the value of a member variable. Properties provide a convenient means to control access to private or protected data.
_ _sealed
_ _sealed
prevents the class that it modifies from being inherited. It can also be used to specify that a virtual function cannot be overridden.
_ _try_cast
_ _try_cast
attempts to cast one type of expression into another. If the cast fails, an exception of type System::InvalidCastException is thrown.
_ _typeof
_ _typeof
obtains an object that encapsulates type information for a given type. This object is an instance of System::Type.
_ _value
_ _value
specifies a class that is represented as a value type. A value type holds its own values. This differs from a _ _gc type, which must allocate storage through the use of
new
. Value types are not subject to garbage collection.
Preprocessor Extensions
To support .NET, Microsoft defines the #using preprocessor directive, which is used to import metadata into your program. Metadata contains type and member information in a form that is independent of a specific computer language. Thus, metadata helps support mixed-language programming. All managed C++ programs must import
<mscorlib.dll>
, which contains the metadata for the .NET Framework.
Microsoft defines two pragmas that relate to the .NET Framework. (Pragmas are used with the #pragma preprocessing directive.) The first is, managed, which specifies managed code. The second is unmanaged, which specifies unmanaged (that is, native) code. These pragmas can be used within a program to selectively create managed and unmanaged code.
A p p e n d i x A : T h e . N E T M a n a g e d E x t e n s i o n s t o C + +
1003
The attribute Attribute
Microsoft defines attribute, which is the attribute used to declare another attribute.
Compiling Managed C++
At the time of this writing, the only compiler commonly available that can target the
.NET Framework is the one supplied by Microsoft’s Visual Studio .NET. To compile a managed code program, you must use the /clr option, which targets code for the
Common Language Runtime.
This page intentionally left blank
Appendix B
C++ and the
Robotics Age
1005
Copyright © 2003 by The McGraw-Hill Companies. Click here for terms of use.
1006
C + + : T h e C o m p l e t e R e f e r e n c e
I have had a long term interest in robotics, especially robotic control languages. In fact, years ago I designed and implemented industrial robotic control languages for use on small educational robots. Although I no longer work professionally in the area of robotics, it remains an important and engaging special interest of mine. Over the years
I have seen the capabilities of robots (and the code that controls them) make major leaps forward. We now stand at the beginning of the robotics age. There are already robots that can mow the lawn and vacuum the floor. They assemble our cars and work in environments dangerous to humans. Battlefield robots are now becoming a reality.
Many more robotic applications are on the way. As robots become more commonplace, integrating themselves into the fabric of everyday life, increasing numbers of programmers will find themselves writing robotic control code. And, much of that code will be in C++.
C++ is a natural choice for robotic programming because robots require efficient, high-performance code. This is especially true for the low-level motor control routines, and for such things as vision processing, where speed is quite important. Although some parts of a robotic subsystem, such as a natural language processor, may be written in a language such as C#, the low-level code will almost certainly remain in C++. C++ and robotics go hand-in-hand.
If you are interested in robotics, especially if you are interested in creating your own robot for experimentation, then you might find the robot in Figure B-1 of interest. This is my current test robot. Several things make this robot interesting. First, it contains an
Figure B-1.
A simple, yet effective experimental robot (Photo by Ken Kaiser)
A p p e n d i x B : C + + a n d t h e R o b o t i c s A g e
1007 on-board microprocessor that provides basic motor control and sensor feedback.
Second, it contains an RS-232 transceiver that is used to receive instructions from the main computer and return results. This approach enables a remote computer to provide the intensive processing that is necessary in robotics without adding all that weight to the robot, itself. Third, it contains a video camera that is connected to a wireless video transmitter.
The robot is built on a Hobbico M1 Abrams R/C tank chassis. (I have found that the chassis of R/C model tanks and cars often work well as a robot base.) I removed most of the internals from the tank, including the receiver and speed controls, but I kept the motors. The Hobbico tank is well suited for a robotics platform because it is quite strong, the motors are good, it can carry a lot of weight, and its tank treads don’t fall off. Also, by using tank treads, the robot has a zero turning radius and can run on uneven ground.
The chassis is about 18 inches long and about 8 inches wide.
Once the chassis was empty, I added the following components. To provide on-board control, I used a BASIC Stamp 2, which is a simple, yet powerful microprocessor manufactured by Parallax. Inc. (www.parallaxinc.com). The RS-232 transceiver is also from Parallax, as is the video camera and transmitter. Both the wireless RS-232 transceiver and the video transmitter have a range of about 300 feet. I also added electronic speed controllers for the tank motors. They are of the type used by high-performance R/C cars. They are controlled by the BASIC Stamp microprocessor.
Here is the way the robot works. The remote computer runs the main robotic control program. This program handles all “heavy-duty” processing, such as vision, guidance, and spatial orientation. It can also learn a series of moves and then replay them. The remote computer transmits motion-control instructions (via the wireless RS-232 link) to the robot. The BASIC Stamp receives those instructions and puts them into action. For example, if a “move forward” command is received, the BASIC Stamp sends the proper signals to the electronic speed controllers connected to the motors. When the robot has completed a command, it returns an acknowledgement code. Thus, communication between the remote computer and the robot is bi-directional, and the successful completion of each command can be confirmed.
Because the main processing for the robot occurs on the remote computer, there are no severe limitations to the amount of processing that I can do. For example, at the time of this writing, the robot can follow an object by using its vision system. This capability requires a fair amount of processing that would be difficult to carry on board.
Recently, I have begun work on a robot arm that will be added to the robot. A prototype of the arm is shown in Figure B-2. Although there are several commercial robot arms available to the experimenter and hobbyist, I decided to create my own because I wanted an arm that would be stronger and able to lift heavier objects than was commonly available. The arm uses a stepper motor mounted at its base to turn a long, threaded screw which opens and closes the gripper. This approach allows precise movement along with considerable strength. The arm is controlled by its own Stamp. Thus, the main robot controller simply hands off arm commands to the second Stamp. This allows fully parallel operation of the robot and the arm, and prevents bogging down the main robot controller.
1008
C + + : T h e C o m p l e t e R e f e r e n c e
Figure B-2.
A prototype robot arm (Photo by Ken Kaiser)
Although the main robotic control code will always remain in C++, I am experimenting with migrating a couple of subsystems, including the RS-232 communication routines, to C#. C# offers a convenient interface to IP data transfers and being able to control the robot from a remote location via the Internet is a tantalizing thought.
Index
& (bitwise operator), 43, 44
& (pointer operator), 48, 49,
115-116, 141, 167, 170, 262, 347
& (reference parameter),
340-341, 347
&&, 40, 41, 42
< >, 242, 268, 465, 483
–>, 51, 171, 176, 178, 329, 344 overloading, 407, 413-414
–>* (pointer-to-member operator), 337, 338, 339
* (multiplication operator), 37,
38, 39
* (pointer operator), 48-49,
115-116, 124, 347
* (printf( ) placeholder), 202-203
|, 43, 44
||, 40, 41, 42
[ ], 51-52, 90, 145, 207, 350,
351, 356 overloading, 407-411
^, 43, 45, 207
:, 47, 271, 613
:: (scope resolution operator),
272, 319, 438-439
, (comma operator), 50-51 overloading, 414-416
{ }, 8, 18, 58, 88
. (dot operator), 51, 165, 176,
178, 272, 293, 344
.* (pointer-to-member operator), 337, 338
!, 40, 41, 42
!=, 41, 42
=, 31, 35
= =, 41, 42
<, 41, 42
<< (left shift), 43, 45-46
<< (output operator), 262-264 overloading, 526-532,
794-795
<=, 41, 42
–, 37, 38, 39
– –, 38-39, 389-390, 393-395
( ) used for clarification in expressions, 55-56
( ) function operator, 138 overloading, 407, 411-413
( ) precedence operator, 40,
42, 51
% (format specifier), 195
% (modulus operator), 37, 38, 39
+, 37, 38, 39
++, 38-39, 389-390, 393-395
# (preprocessor directive), 238
# (preprocessor operator),
248-249, 250
# (printf( ) modifier), 202-203
## (preprocessor operator), 248,
249-250
?, 47-48, 63-66
>, 41, 42
>> (right shift), 43, 45-46
>> (input operator), 262,
263-264 overloading, 526, 532-535,
794-795
>=, 41, 42
; (semicolon), 88, 163
/, 37, 38, 39
/* */, 250-251
//, 252, 262
~, 43, 46-48, 285
A abort( ), 489, 490, 500, 503,
504, 762 abs( ), 762-763
_ _abstract keyword, 1000
Access declarations, 434-437
Access specifiers, 290, 418-425 accumulate( ) algorithm,
920-921 acos( ), 738
Ada, 5
Adaptor(s), 633, 876-878
Address, memory
& operator used to return,
48, 115-116 pointer as, 48, 115 relocatable format, 12
1009
Copyright © 2003 by The McGraw-Hill Companies. Click here for terms of use.
1010
C + + : T h e C o m p l e t e R e f e r e n c e adjacent_difference( ) algorithm, 921-922 adjacent_find( ) algorithm, 840 adjustfield format flag, 514 advance( ), 872
Aggregate data type, 162
ALGOL, 6, 8
<algorithm> header, 664
Algorithms, 631, 635, 664-674,
840-859 table of STL, 665-667
Allocation, dynamic. See
Dynamic allocation allocator class, 632, 879-880 member functions, table of, 880
Allocators, 632, 879-880
AND
& bitwise operator, 43, 44
&& logical operator, 40,
41, 42
ANSI/ISO
C standard, 2, 4
C++ standard, 4,
256-257, 267 app, 793 append( ), 688 argc, 144-145, 147
Arguments, function call by reference passing convention, 140-141, 170,
339-343 call by value passing convention, 139-140 command line, 144-147 default, 371-378, 380 passing arrays as, 92-93, 98,
102, 142-144 passing functions as,
126-129 argv, 123, 144-147
Arithmetic operators, 37-40 precedence of, 39
Array(s) allocating with new, 350-351 bounds checking on, 6, 91,
367, 410 compacting, 470-472 definition of, 90 generating pointer to, 92 indexing versus pointer arithmetic, 121-122 initialization, 105-107 multidimensional, 101-102 of objects, 326-329, 354,
364-366 to functions, passing, 92-93,
142-144 of pointers, 122-123 pointers to access, 103-104,
121-122 safe, creating, 367-369,
410-411 single-dimension, 90-91 sorting, 469-470 square brackets as operator for indexing, 51-52 of strings, 100-101 of structures, 166 within structures, 173 two-dimensional, 96-101 unsized, 106-107 variable-length, 4 vector as dynamic, 635
Array-based I/O, 618-626 and binary data, 625-626 using dynamic arrays and,
624-625 using ios member functions with, 619
Arrow operator (–>), 51, 171,
176, 178, 329, 344 overloading, 407, 413-414 asctime( ), 748-749 asin( ), 738-739 asm statement, 616-617
Assembly language, 5, 8-9 using asm to embed,
616-617
C used in place of, 8, 42-43 assert( ), 763 assign( ), 687-688
Assignment compound, 56 functions used in, 150,
344-345 multiple, 37 object, 324 operation for C++ classes, default, 389 operator, 35 pointer, 117, 332 shorthand, 56, 390 structure, 165-166 type conversion in, 35-37 atan( ), 739 atan2( ), 739 ate, 793 atexit( ), 763 atof( ), 763-764 atoi( ), 146, 764 atol( ), 764 attribute, 1003 auto keyword, 18 auto_ptr class, 928-930
B
B language, 4 back_insert_iterator class,
866, 867
Backslash character constants,
33-34 bad( ), 563, 795 bad_alloc class, 348, 926 bad_cast, 578, 927 bad_exception class, 506, 926 bad_typeid, 572, 926 badbit, 561, 563, 794, 803
Base class access control, 418-424 constructors, passing parameters to, 430-434 definition of, 278, 418 general form for inheriting,
279-280, 418 inheritance, protected,
424-425 virtual, 437-441 base( ), 868 basefield format flag, 514
BASIC, 5, 6, 7, 8 basic_filebuf class, 788, 789 basic_fstream class, 512,
788, 789 basic_ifstream class, 512,
788, 789 basic_ios class, 511, 512, 788, 789
I n d e x
1011 basic_iostream class, 511, 512,
788, 789 basic_istream class, 511, 512,
788, 789 basic_istringstream class,
788, 789 basic_ofstream class, 512,
788, 789 basic_ostream class, 511, 512,
788, 789 basic_ostringstream class,
788, 789 basic_streambuf class, 511, 512,
788, 789 basic_string class, 683, 882-894 constructors, 882 member functions, table of,
884-894 basic_stringbuf class, 788, 789 basic_stringstream class, 788,
789
BCPL language, 4 before( ), 568-569 beg, 794 begin( ), 635, 636, 637, 641
BiIter, 632, 812 binary, 793 binary_function class, 679,
873, 874 binary_negate class, 875-876 binary_search( ) algorithm,
840-841 bind1st( ) binder, 680-681,
874-875 bind2nd( ) binder, 680-681,
874-875
Binders, 633, 680-682, 874-875
BinPred type, 632, 812
Bit shift operators (>> and <<),
43, 45-46
Bit-fields, 162, 174-176 bitset container, 633, 634, 812,
814-816 member functions, table of,
815-816
<bitset> header, 633, 812
Bitwise operation, definition of, 43
Bitwise operators, 42-47 table of, 43
Block statements, 58, 88 bool data type, 14, 40, 58,
59, 266
_Bool data type, 59, 266 boolalpha format flag, 514 manipulator, 522,
525-526, 791
_ _box keyword, 1001 break statement, 67, 68, 69-70,
76, 83-85
Broken-down time, 748 bsearch( ), 764-765
BUFSIZ macro, 719
C
.C file extension, 12
C Programming Language, The
(Kernighan & Ritchie), 4
C standard, ANSI/ISO, 2, 4
C89, 4-5
C99, 4-5
C++ differences between C and,
130, 626-627 differences between old-style and modern,
267-270 origins of, 256-257 and robotics, 1006, 1008 sample program, 260-263
Standard, 4, 257, 267 c_str( ), 692
Calendar time, 748
Call by reference, 140-141 automatic, using reference parameter, 339-343 structure pointers used for, 170
Call by value, 139-140 calloc( ), 758
Case sensitivity, 10, 17, 287 case statement, 67, 69-70
<cassert> header, 763
Casts, 54-55 and base class pointers,
334, 335
C++ operators for, 55,
578-589 and pointers, 116, 130-131 catch statement, 488-500, 502 catch(...) form of, 498-500 and derived-class exceptions, 497 general form of, 488 using multiple, 495-496
<cctype> header, 724 ceil( ), 739-740 cerr, 512
<cerrno> header, 738 char data type, 14, 15 char_traits class, 789, 882,
894-896 member functions, table of,
895-896
Character(s)
ASCII, 14, 547 in C console I/O, 189-191 constants, 32, 626 constants, backslash, 33-34 control, 724 printable, 724 set, extended, 547-548 wide. See Wide character(s)
Character translations in C I/O, 213, 217, 706 in C++ file I/O, 545, 557 cin, 262, 512
Class(es) abstract, 455 access specifications,
290-292 base. See Base class creating conversion functions for, 603-607 declaration, general form for, 271-272, 290 defining functions within,
306-307, 309 derived. See Derived class forward declaration of, 300 friend, 302-303 generic. See Generic class instance of, 271 libraries, 458 local, 320-321
1012
C + + : T h e C o m p l e t e R e f e r e n c e nested, 319 overview of, 270-274 stream, 511-512 structures and, 293-295 unions and, 295-297 class keyword, 270, 290, 295
Class member(s) accessing, public,
272-273, 293 definition of, 271, 292 initialization syntax,
611-616 pointers to, 337-339 restrictions on, 292-293 static, 310-317 clear( ), 795 clearerr( ), 700
<climits> header, 14
<clocale> header, 748 clock( ), 749 clock_t type, 748
CLOCKS_PER_SEC, 748, 749 clog, 512 close( ), 542
<cmath> header, 738
COBOL, 5, 7, 8
Code block, 8, 18-20 compartmentalization of,
6-7, 8 managed (.NET
Framework), compiling,
1000, 1003
Comma operator, 50-51 overloading, 414-416
Command line arguments,
144-147
Comments in C89, 250-251 in C++ and C99, 4, 252, 262
Common Language Runtime
(CLR), 1000, 1003
Comp type, 632, 812 compare( ), 692
Compilation conditional, 242-246 separate, 12, 27
Compilers compiling C programs with
C++, 12 working with older C++, 270 complex class, 898-901 functions defined for, table of, 900-901
<complex> header, 898
Compound data types, 162
Compound statements, 58, 88
Conditional expression, 58,
66-67
Conglomerate data type, 162 conio.h header file, 191 const qualifier, 23-24, 25
Constants, 32-34 const_cast, 586-588
Constructor(s), 283-287 copy, 322-323, 324, 366-369 and default arguments,
375-376 execution order of, 317-318,
426-430 explicit, 610-611 and inheritance, 426-434 and member initialization syntax, 613-616 overloading, 362-369 parameterized, 307-310 passing parameters to base class, 430-434 container protected variable, 867
Containers, 630-631, 812-837 defined by STL, table of,
633, 812-813 string class and, 693-695 typedef names for, 634,
813-814 continue statement, 86-87 copy( ) algorithm, 841 copy_backward( ) algorithm,
841 cos( ), 740 cosh( ), 740 count( ), algorithm, 664, 665,
668-669, 841 count_if( ) algorithm, 664, 665,
668, 669-670, 842 cout, 262, 512
_ _cplusplus predefined macro, 250
.CPP file extension, 12
<csetjump> header, 767, 770
<cstdarg> header, 722, 774
<cstdio> header, 188, 214-215,
700, 719, 721
<cstdlib> header, 59, 758, 762
<csignal> header, 769, 771
<cstring> header, 94, 724 ctime( ), 749
<ctime> header, 748 ctype.h header file, 724 cur, 794 current protected member, 868
<cwchar> header, 776, 779,
782, 783
<cwctype> header, 776
D
Data compartmentalization of, 6-7 in expressions, 14
Data type(s) aggregate, 162, 173
ANSI/ISO C, table of, 15 basic, 14-15 class as, 271 conversion of, in assignments, 35-37 conversion of, in expressions, 6, 53-54 creating and integrating new C++, 961 definition of, 6 modifiers for basic, 15-16
_ _DATE_ _ predefined macro, 250 dec format flag, 514, 791 manipulator, 522, 791
Decrement operator (– –), 38-39 overloading for prefix and postfix, 389-390, 393-395 default statement, 67
#define directive, 238-241 and function-like macros,
240-241
I n d e x
1013 and preprocessor operators
# and ##, 248-250 defined compile-time operator,
247-248
_ _delegate keyword, 1001 delete dynamic allocation operator, 347-357, 758 and arrays, 350-351 and arrays of objects, 356 overloading, 398-403,
406-407 overloading for arrays,
403-406 deque container, 630, 633,
634-635, 812, 816-818 member functions, table of,
817-818
<deque> header, 633, 812
Derived class access declaration within,
434-436 creating, 279 definition of, 278, 418 inheriting multiple base classes, 425-426 objects, base class pointers to, 334-336
Destructors, 284-287 execution order of, 317-318,
426-430 and inheritance, 426-430 difference_type, 863 difftime( ), 750 distance( ), 872 div( ), 762, 765-766 div_t type, 762, 765 divides( ) function object,
677-678 do-while loop, 7, 79-81 domain_error exception, 928
Dot operator (.), 51, 165, 176,
178, 272, 293, 344 double data type, 14, 15
Dynamic allocation, 129-131 functions for, 130-131,
758-759 operators for, 347-357, 758 dynamic_cast, 578-586
E
Early binding, 458
EDOM, 738
#elif directive, 243, 244-245, 248 else, 59
#else directive, 243-245 empty( ), 646, 655
Encapsulation, 258, 265 class as basic unit of, 290 and global variables, 315 how to achieve, 271, 292 end, 794 end( ), 635, 636, 637, 641,
649-651
#endif, 243-245 endl manipulator, 522, 791 ends manipulator, 522, 791 enum keyword, 180
Enumerations, 162, 180-182
EOF macro, 189, 215, 220, 700 eof( ), 553-555, 563, 625, 795-796 eofbit, 794, 803 equal( ) algorithm, 842 member function, 870 equal_range( ) algorithm, 842
ERANGE, 738, 772, 773 erase( ), 634, 636, 637, 641,
688-689 errno, 700, 738, 772, 773 errno.h header file, 738
Error checking, run-time, 6
#error directive, 241
Errors pointer, 131-135
See also Exception handling
Escape sequences, 33
_ _event keyword, 1001 exception class, 506, 794,
926-927
Exception handling, 348,
488-507 applying, 506-507 and catching all exceptions,
498-500 classes, 926-928 fundamentals, 488-497 and restricting exceptions,
500-502 and rethrowing exceptions,
502-503
<exception> header, 503, 504,
506, 926-927 exceptions( ), 796
Exclusive OR. See XOR exit( ), 85-86, 150, 490, 766
EXIT_FAILURE, 263, 762, 766
EXIT_SUCCESS, 263, 762, 766 exp( ), 740 explicit specifier, 610-611 export keyword, 485
Expression(s), 52-56 conditional, 58, 66-67 definition of, 14, 52 evaluation order, 52, 65 function calls used in, 64-65,
149-150 parser, 964-997 pointer, 116-120 production rules of, 966-967 statements, 58, 88 tokens, 969 type conversion in, 53-54 extern storage class specifier,
25-27, 618
Extractors, creating, 526,
532-535
F fabs( ), 741 facet class, 931 fail( ), 563, 796 failbit, 561, 563, 794, 803 failed( ), 872 failure class, 794 false, 40, 58, 266 fclose( ), 150, 217, 218-220, 701 feof( ), 220-221, 701 ferror( ), 224-225, 701-702 fflush( ), 226-227, 702 fgetc( ), 218, 702 fgetpos( ), 702-703 fgets( ), 192, 222, 232-233, 703
File(s), C in C I/O system, 213-214 closing, 217 control structure, 213 erasing, 226
1014
C + + : T h e C o m p l e t e R e f e r e n c e opening, 215-217, 703-705 pointer, 215, 216, 217
File(s), C++ closing, 542 get pointer, 557, 561 opening, 540-542 put pointer, 557, 561 reading and writing unformatted and binary,
545-553 reading and writing text,
543-545
FILE data type, 213, 215, 700
File position indicator, 213,
702-703, 708 resetting, 223-224, 715 setting, 229-230
_ _FILE_ _ predefined macro,
248, 250 filebuf class, 540, 790 fill( ) algorithm, 843 member function,
521-522, 796 fill_n( ) algorithm, 843
_ _finally keyword, 1001 find( ) algorithm, 843 member function, 635, 659,
662, 690-692 find_end( ) algorithm, 843 find_first_of( ) algorithm,
843-844 find_if( ) alogrithm, 844 fixed format flag, 514, 791 manipulator, 522, 791 flags( ), 518-520, 797 float data type, 14, 15 floatfield format flag, 514, 791
Floating-point constants, 32-33 floor( ), 741 flush manipulator, 522, 791 flush( ), 556-557, 797 fmod( ), 741 fmtflags enumeration, 513, 791 fopen( ), 215-217, 218-220, 233,
703-705
FOPEN_MAX macro, 215, 217 for loop, 7, 70-77 declaring variable within, 81 general form of, 70-71 infinite, 76 variations of, 72-76 with no body, 77 for_each( ) algorithm, 844
ForIter, 632, 812
Formal parameters. See
Parameters, formal
Format flags, 513-520, 791
Forth, 5
FORTRAN, 5, 7, 257
Forward declaration, 300 fpos_t data type, 215, 700 fprintf( ), 230-232, 544, 705 fputc( ), 217, 705 fputs( ), 222, 705 fread( ), 227-228, 235, 706 free( ), 130-131, 348, 349,
758-759 freeze( ), 625 freopen( ), 234-235, 706-707 frexp( ), 741-742
Friend classes, 302-303
Friend functions, 297-302 and the this pointer, 334, 391 friend keyword, 298 front_insert_iterator class,
866, 867 fscanf( ), 230-232, 544, 707 fseek( ), 215, 229-230, 707-708 fsetpos( ), 708 fstream class, 512, 540, 790
<fstream> header, 540, 790, 791 fstream( ), 797-798 ftell( ), 230, 708-709
Function(s), 7-8, 10 arguments. See Arguments, function conversion, creating,
603-607 formal parameters of. See
Parameters, formal friend. See Friend functions general form of, 138 generic. See Generic function(s) inline. See Inline functions library, 10-12, 697-698 main( ). See main( ) member. See Member functions objects. See Function objects passing multidimensional arrays to, 98, 102 passing objects to, 320-323 passing single-dimension arrays to, 92-93 passing structures to,
167-169 pointers to, 126-129 prototypes, 155-157, 626 predicate, 632 recursive, 153-155 return type, default to int, 266 returning from, 148-149 returning objects from,
323-324 returning pointers from,
151-152 returning references from,
344-345 returning values from,
149-151 scope rules of, 138-139 stand-alone, 7-8, 28 used in assignment statement, 344-345 used in expressions, 64-65,
149-150 virtual. See Virtual functions void, 150, 152-153
Function objects, 632-633,
675-682, 872-878 built-in, list of, 632, 675, 873 using binders with, 680-682,
874-875 creating, 678-680, 873
Function overloading, 275-278,
360-371 and ambiguity, 378-381 and constructors, 362-369
I n d e x
1015 and function pointers,
370-371 versus default arguments,
376-377
<functional> header, 632-633,
675, 872 fwide( ), 779 fwrite( ), 179, 227-228, 235, 709
G
Garbage collection, 1001
_ _gc keyword, 1001 gcount( ), 550-551, 798 generate( ) algorithm, 844-845 generate_n( ) algorithm,
844-845
Generated function, 462
Generic class, 472-484 creating safe array with,
477-480 default arguments and, using, 481-483 explicit specialization of,
483-484 general form of, 473 using non-type arguments in, 479-480 typeid and, 576-578
Generic function(s), 460-472 applying, 468-472 explicitly overloading,
463-465 general forms of, 460, 462 restrictions, 467-468 get( ), 546-547, 625, 798-799 member function of auto_ptr, 929-930 overloaded forms of, 551
Get pointer, 557, 804, 808 getc( ), 218, 219-220, 709 getch( ), 190-191, 193 getchar( ), 189-191, 192, 193,
205, 710 getche( ), 190-191, 193 getenv( ), 766 getline( ), 551-553, 799-800 gets( ), 143, 144, 192, 193, 205,
222, 232, 710 gmtime( ), 750 good( ), 563, 800 goodbit, 561, 563, 794, 803 goto statement, 7, 83, 138 greater( ) function object,
680-682 gslice class, 917, 919-920 gslice_array class, 920
H
Headers and header files, 27,
157, 242, 261, 268-269, 603
Heap, 130, 131, 758 hex format flag, 514, 791 manipulator, 522, 791
Hexadecimal constants, 33
Hierarchical classifications, 418
Hoare, C.A.R., 769
HUGE_VAL macro, 738, 772
I
_ _identifier keyword, 1001
Identifiers, 16-17, 626
#if directive, 243-244, 245, 247 if statement declaring variable within,
81-82 general form of, 59 if-else-if ladder, 62-63 nested, 60-62
? as alternative to, 63-66
#ifdef directive, 245-246
#ifndef directive, 245, 246 ifstream class, 512, 540, 790 ifstream( ), 797-798 ignore( ), 555-556, 800 imag( ), 899 in, 793
#include directive, 242, 268, 269 includes( ) algorithm, 845
Increment operator (++), 38-39 overloading for prefix and postfix, 389-390, 393-395 indirect_array class, 920
Inheritance, 259, 278-283,
418-441 access declaration in,
434-437 access specifiers and,
418-425 constructors, destructors, and, 426-434 multiple base class, 425-426 and virtual base classes,
437-441 and virtual attribute of functions, 448-450
InIter, 632, 812
Inline functions, 303-307 within a class, defining,
305-306 inline keyword, 241, 303, 306 and C99, 305 inner_product( ) algorithm,
922-923 inplace_merge( ) algorithm, 845
Input operator (>>), 262,
263-264 overloading, 526, 532-535,
794-795 insert( ), 634, 636, 637, 641, 643,
646, 648, 688, 689 insert_iterator class, 864-866 inserter( ), 865
Inserters, creating, 526-532 int data type, 14, 15 default to, 265-266, 627 unsigned versus signed, 16
Integers signed vs. unsigned, 16 size of, 14
_ _interface keyword, 1001 internal format flag, 513, 791 manipulator, 522, 792 int_type data type, 555 invalid_argument exception, 928
I/O, C-style, 188 functions, 700-722, 779, 780
I/O, C console, 188-209 basic functions for, table of, 193 and characters, 189-191 formatted, 195-209 and strings, 191-194
I/O, C file, 212-235 common functions for, table of, 214
1016
C + + : T h e C o m p l e t e R e f e r e n c e connection with console
I/O, 233-234 files in, 212, 213-214. See also
File(s), C formatted, with fprintf( ) and fscanf( ), 230-232 random-access, 229-230 reading and writing a character in, 217-218 reading and writing blocks of data in, 227-228 streams in, 212-214.
See also Streams and strings, 222
I/O, C++ array-based. See
Array-based I/O byte-oriented vs.
character-oriented,
545-546 formatted, 513-526 functions, 795-809 headers, 790-791 manipulators. See
Manipulators old vs. modern, 510 operators. See Operators,
I/O predefined streams, 512-513 streams, 511 template classes, 511-512,
788-790
I/O, C++ file, 540-566 customized I/O and,
563-566 flushing buffers in, 556-557 random access, 557-561, 814 status, obtaining, 561-563
See also Files, C++
_IOFBF, 719
_IOLBF, 719
<iomanip> header, 523, 790,
791, 792
_IONBF, 719 ios class, 512, 540, 619, 789
<ios> header, 790 ios::app, 541, 801 ios::ate, 541, 801 ios::badbit, 561 ios::beg, 557, 804 ios::binary, 541, 545, 801 ios::cur, 557, 804 ios::end, 557, 804 ios::eofbit, 561 ios::failbit, 561 ios::goodbit, 561 ios::in, 541, 801 ios::out, 541, 801 ios::trunc, 541, 801 ios_base class, 511, 788, 789
<iosfwd> header, 790, 793 iostate enumeration, 561, 794 iostream class, 512, 619, 789
<iostream> header, 260, 278,
510, 512, 790, 791 iostream.h header file, 510 is_open( ), 542 isalnum( ), 724 isalpha( ), 724 iscntrl( ), 725 isdigit( ), 725 isgraph( ), 725 islower( ), 725-726 isprint( ), 726 ispunct( ), 726 isspace( ), 726 istream class, 512, 532, 619, 789
<istream> header, 790 istream_iterator class, 868-869 istream_type type, 869, 870 istreambuf_iterator class, 869 istringstream class, 790 istringstream( ), 806-807 istrstream class, 619, 621, 622 isupper( ), 727 iswctype( ), 776-778 isxdigit( ), 727
Iteration statements, 58, 70-81 declaring variables within, 81
Iterator(s), 631, 635, 639-641,
812, 862-872 functions, 872 predefined, 864-872 iterator class, 863 type, 631, 641, 863
<iterator> header, 862, 863 iterator_category type, 863 iterator_traits class, 864 iter_swap( ) algorithm, 845
J
Java, 5, 7 jmp_buf type, 767
Jump statements, 58, 68, 82-87
K kbhit( ), 84
Kernighan, Brian, 4
Keywords
C, 6, 8
C89, table of, 10
C++, table of, 287-288 extended, common, 10
.NET Framework extensions to C++, 1000-1002
L
L_tmpnam, 721
Label identifier for goto statement, 83 statements, 58, 67 labs( ), 766
Language(s), computer block-structured, 6, 139 high-level, 5-6 middle-level, C as, 5-6 programmer’s, C as, 8-9 structured, C as, 6-8,
257-258
Late binding, 458
LC_ALL, 753
LC_COLLATE, 753
LC_CTYPE, 753
LC_MONETRAY, 753
LC_NUMERIC, 753
LC_TIME, 753
I n d e x
1017 lconv structure, 750-751 ldexp( ), 742 ldiv( ), 762, 767 ldiv_t structure, 762,
765-766, 767 left format flag, 513, 791 manipulator, 522, 792 length_error exception, 928 less( ) function object, 632,
633, 658 lexicographical_compare( ) algorithm, 846
Library class, 11, 458, 785-786, 898 standard function, 10-12,
697-698 standard template. See
Standard template library (STL)
<limits> header, 931
#line directive, 248
_ _LINE_ _ predefined macro,
248, 250
Line-buffered input, 190
Linkage categories of, 25 specification, 617-618
Linker, 12, 27 list container, 630, 633, 634-635,
645-657, 812, 819-822 member functions, table of,
646-647, 819-822
<list> header, 633
Literals, 32 locale class, 931
<locale> header, 931 locale.h header file, 748 localeconv( ), 750-752
Localization
C functions for, 748,
750-751, 752-754 class library, 931 localtime( ), 752 log( ), 742 log10( ), 742-743 logic_error class, 928
Logical operators, 40-42 truth table for, 40 long modifier, 15-16
LONG_MAX, 772
LONG_MIN, 772 longjmp( ), 507, 767, 770
Loops do-while, 7, 79-81 for. See for loop infinite, 76 and structured languages, 7 time delay, 77 while, 7, 77-79 with no bodies, 77 lower_bound( ) algorithm, 846 lvalue, 35
M
Macro function-like, 240-241 name, 238 predefined, 250 replacement, 238 main( ), 10, 156, 627 argc and argv as arguments to, 144-147 return value from, 153 using void in parameter list of, 147 make_heap( ) algorithm, 846-847 make_pair( ), 660-661, 662,
930-931 malloc( ), 130-131, 348, 349, 356,
758, 759 managed pragma, 1002
Manipulators creating custom, 535-538 to format I/O, using,
522-526 table of C++, 522-523,
791-792 map container, 631, 633, 634,
658-664, 813, 822-824 member functions, table of,
659-660, 823-824
<map> header, 633, 813 mask_array class, 920 math.h header file, 738 max( ) algorithm, 847 max_element( ) algorithm, 847
MB_CUR_MAX, 762, 774 mblen( ), 767-768 mbstate_t type, 776, 783 mbstowcs( ), 768 mbtowc( ), 768 mem_fun( ) adaptor, 877 mem_fun_ref( ) adaptor, 878 mem_fun_ref_t class, 878 mem_fun_t class, 877-878 mem_fun1( ) adaptor, 877 mem_fun1_ref( ) adaptor, 878 mem_fun1_ref_t class, 878 mem_fun1_t class, 877-878
Member functions, 271, 272, 292 const, 607-609 and scope resolution operator, 272 static, 315-317 and the this pointer, 332-334 volatile, 609 within class, defining,
306-307, 309
Member variables, 271, 272,
292, 293 initialization syntax for,
611-616 static, 310-315 memchr( ), 727 memcmp( ), 727-728 memcpy( ), 728 memmove( ), 728
<memory> header, 879, 928, 931 memset( ), 729 merge( ), 647, 648, 653-655 algorithm, 847-848
Metadata, 1002
Microsoft Intermediate
Language (MSIL), 1000 min( ) algorithm, 848 min_element( ) algorithm, 848 mismatch( ) algorithm, 848-849 mktime( ), 752 modf( ), 743
Modula-2, 5, 6, 7, 8
<mscorlib.dll>, 1002
1018
C + + : T h e C o m p l e t e R e f e r e n c e multimap container, 633, 634,
658, 813, 824-826 member functions, table of,
825-826 multiset container, 633, 634,
813, 827-829 member functions, table of,
827-829 mutable keyword, 25, 608-609
N name( ), 568, 569
Namespace, 30, 261, 269-270,
592-603 unnamed, 598-599 namespace statement, 267, 270,
592-593
NDEBUG, 763 negate( ) function object, 675,
676-677
Negators, 633, 682, 875-876
.NET Framework, 1000-1003
C++ keyword extensions,
1000-1002 preprocessor extensions,
1002 new dynamic allocation operator, 347-357, 758, 926 and allocating arrays,
350-351 and allocating objects,
351-356 and initializing memory,
349-350 overloading, 398-403,
406-407 overloading for arrays,
403-406 placement form of, 357
<new> header, 348, 356 next_permutation( ) algorithm, 849 noboolalpha manipulator,
522, 792
_ _nogc keyword, 1001 noshowbase manipulator,
522, 792 noshowpoint manipulator,
522, 792 noshowpos manipulator,
522, 792 noskipws manipulator, 523, 792 nounitbuf manipulator, 523, 792 nouppercase, 523, 792
NOT
! logical operator, 40, 41, 42
~ bitwise operator, 43, 46-48 not1( ) negator, 682, 875 not2( ) negator, 682, 875 nothrow option for new, 356 overloading, 406-407 nothrow_t data type, 407 npos constant, 685, 863 nth_element( ) algorithm, 849
Null definition of, 94 statement, 88
NULL macro, 215, 762
Numeric classes, 898-924 constants, 32-33 numeric_limits class, 931
O
Object(s) allocating, 351-356 arrays of, 326-329, 354,
364-366 assignment, 324 base class pointers to derived class, 334-336 base class references to dervied class, 346 creating, 271 definition of, 258, 290 factory, 574 function. See Function objects to functions, passing,
320-323 from functions, returning,
323-324 initialization, 283, 307, 309,
310, 367 passing references to,
343-344 pointers to, 329-331
Object-oriented programming
(OOP), 256, 257-259 oct format flag, 514, 791 manipulator, 523, 792
Octal constants, 33 off_type type, 793, 804 ofstream class, 512, 540, 790 ofstream( ), 797-798
One’s complement operator (~),
43, 46-48
OOP (Object-oriented programming), 256, 257-259 open( ), 540-542, 800-801 openmode, 541, 793
Operator(s) arithmetic, 37-40 arrow. See Arrow operator (–>) assignment, 35 bitwise, 42-47 casting, 54-55, 578-589 comma, 50-51 compile-time, 50 dot, 51, 165, 176, 178, 272,
293, 344 dynamic allocation, 347-357 pointer, 48-49, 115-116, 347 pointer-to-member (.* and
–>*), 337, 338, 339 precedence of C, 52, 53 relational and logical, 40-42 scope resolution, 272, 319,
438-439 ternary (?), 47-48, 63-66 operator functions creating member, 384-391 definition of, 384 using friend, 391-398 operator keyword, 384
Operator overloading, 278,
384-416
[ ], ( ), and –>, 407-414 comma, 414-416
I n d e x
1019 increment and decrement,
389-390, 393-395 new and delete, 398-407, 758 restrictions, 390-391 shorthand, 390
See also operator functions operator( ), 632, 675, 678-680,
872, 876, 877
Operators, I/O (<< and >>),
262-264 overloading, 526-535,
794-795
OR bitwise operator (|), 43, 44 logical operator (||), 40,
41, 42 ostream class, 512, 526, 619, 789
<ostream> header, 790 ostream_iterator class, 870-871 ostream_type, 870, 872 ostreambuf_iterator class,
871-872 ostringstream class, 790 ostringstream( ), 806-807 ostrstream class, 619, 624 out, 793 out_of_range exception, 928
OutIter, 632, 812
Output operator (<<), 262-264 overloading, 526-532,
794-795 overflow_error exception, 928 overload keyword, 287, 371
Overloading functions. See
Function overloading
Overloading operators. See
Operator overloading
Overriding versus function overloading, 446-447
P pair template class, 632, 660,
662, 930-931
Paragraph alignment, 183
Parallax, Inc., 1007
Parameters, formal, 21, 139, 626 declarations, classic versus modern, 158-159 reference, 141, 339-343, 346 variable number of, 158
Parity bit, 43, 44 partial_sort( ) algorithm,
849-850 partial_sort_copy( ) algorithm, 850 partial_sum( ) algorithm,
923-924 partition( ) algorithm, 850
Pascal, 5, 6, 257 pcount( ), 620 peek( ), 556, 801 perror( ), 710-711
_ _pin keyword, 1002 plus( ) function object, 675
POD (Plain Old Data), 295, 296
Pointer(s), 114-135 accessing arrays with,
103-104, 121-122 arithmetic, 103, 117-118 to arrays, generating, 92 arrays of, 122-123 assignments, 117, 332 base type of, 49, 115, 118
C file, 215, 216, 217
C++ file, 557 to class members, 337-339 comparisons, 119-120, 133 definition of, 48, 114 to derived class objects,
334-336 dynamic allocation and,
129-131 to functions, 126-129 indexing, 102-104 initializing, 125-126, 132,
134-135 to objects, 329-331 operators, 48-49,
115-116, 347 to pointers, 123-124 problems with, 131-135 returned from functions,
151-152 structure, 169-173 this, 315, 332-334 typeid and base-class,
570-572 void*, 130 pointer type, 863 pointer_to_binary_function class, 876-877 pointer_to_unary_function class, 876, 877
Polymorphism, 258-259 through function overloading, 275, 276, 360 through operator overloading, 278
Polymorphism, run-time through inheritance and virtual functions, 283,
336, 444, 446, 455-458 through RTTI and casting operators, 568 pop_back( ), 634 pop_front( ), 635 pop_heap( ) algorithm, 850-851
Portability, 6 using sizeof to ensure,
183-184 using typedef to aid,
184-185 pos_type data type, 561, 793, 804 pow( ), 743
#pragma directive, 248 precision( ), 520-522, 802
Predicate functions, 632
Preprocessor directives, 238-248
Preprocessor operators, 248-250 prev_permutation( ) algorithm, 851 printf( ), 117, 134, 192, 195-203,
233, 711-713 in C++ program, 262 format specifiers, table of,
195-196, 712 return value of, 150, 195, 711 priority_queue container, 633,
813, 830-831 member functions, table of, 831 private access specifier, 290, 418 effects of, 419-420
Program(s) general form of C, 10, 11 general form of C++, 288 systems, 9
1020
C + + : T h e C o m p l e t e R e f e r e n c e
_ _property keyword, 1002 protected access specifier, 290,
418, 420 effects of, 420-425
Prototypes, function,
155-157, 626 ptr_fun( ) adaptor, 876-877 ptrdiff_t type, 664, 842, 863 public access specifier, 271,
290, 418 effects of, 418-419 push_back( ), 634, 636, 637, 646,
647, 649, 651-652, 867 push_front( ), 635, 647, 648,
651-652, 867 push_heap( ) algorithm, 851
Put pointer, 557, 804, 808 put( ), 546, 547-548, 626, 802 putback( ), 556, 802 putc( ), 217-219, 714 putchar( ), 189-190, 193, 232, 714 puts( ), 192-194, 714
Q qsort( ), 768-769 queue container, 633, 813,
829-830 member functions, table of,
829-830
<queue> header, 633, 813
Quicksort, 155, 769
R raise( ), 769 rand( ), 59, 574, 770
RAND_MAX, 59, 762, 770
RandIter, 632, 812
Random-access I/O, 229-230,
557-561, 804 random_shuffle( ) algorithm,
851-642 range_error exception, 928 raw_storage_iterator class, 931 rdstate( ), 561-563, 802-803 read( ), 548-551, 626, 803 readsome( ), 803-804 real( ), 899 realloc( ), 758, 759
Recursion, 153-155
Reference(s) definition of, 339 independent, 345-346 to objects, passing, 343-344 parameters, 339-343, 346,
393-394 restrictions, 347 returning, 344-345 typeid and, 572-573 and virtual functions,
447-448 reference type, 863 register storage class specifier,
30-31, 627 reinterpret_cast, 588-589
Relational operators, 40-42 release( ), 929
Relocatable format, 12 remove( ), 226, 715 algorithm, 852 remove_copy( ) algorithm, 666,
670-672, 852 remove_copy_if( ) algorithm,
852 remove_if( ) algorithm, 666,
681-682, 852 rename( ), 715 replace( ), 688, 689 algorithm, 852-853 replace_copy( ) algorithm, 666,
670-672, 852-853 replace_copy_if( ) algorithm,
852-853 replace_if( ) algorithm, 852-853 resetiosflags manipulator,
523, 792 restrict qualifier, 4 return statement, 82 using to return from a function, 148-149 using to return a value, 149 reverse( ) algortihm, 667,
672-673, 853 reverse_copy( ) algorithm, 853 reverse_iterator class, 868 rewind( ), 223-224, 715 rfind( ), 690-692
Richards, Martin, 4 right format flag, 513, 791 manipulator, 523, 792
Ritchie, Dennis, 4
Robotics, 1006-1008 rotate( ) algorithm, 853 rotate_copy( ) algorithm,
853-854
Run-time type identification
(RTTI), 568-578 runtime_error class, 928 rvalue, 35
S
Scalar, 59 scanf( ), 195, 203-209, 262,
715-719 format specifiers, table of,
204, 716
Scanset, 206-207, 718-719 scientific format flag, 514, 791 manipulator, 523, 792
Scope resolution operator (::),
272, 319, 438-439
Scope rules, 138
_ _sealed keyword, 1002 search( ) algorithm, 854 search_n( ) algorithm, 854
SEEK_CUR macro, 215, 229, 708
SEEK_END macro, 215, 229, 708
SEEK_SET macro, 215, 229,
230, 708 seekdir enumeration, 557,
794, 804 seekg( ), 557-560, 804 seekp( ), 557-560, 804
Selection statements, 58, 59-70 declaring variables within,
81-82 set container, 633, 634, 813,
831-833 member functions, table of,
832-833
I n d e x
1021
<set> header, 633, 813 set_difference( ) algorithm,
854-855 set_intersection( ) algorithm, 855 set_symmetric_difference( ) algorithm, 855-856 set_terminate( ), 504 set_unexpected( ), 504 set_union( ) algorithm, 856 setbase manipulator, 523, 792 setbuf( ), 719 setf( ), 514-515, 805 overloaded, 516-518 setfill manipulator, 523, 792 setiosflags( ) manipulator, 523,
525, 792 setjmp( ), 507, 767, 770 setlocale( ), 752-753 setprecision manipulator,
523, 792 setvbuf( ), 719-720 setw manipulator, 523, 792 short modifier, 15-16
Shorthand assignment operators, 56, 390 showbase format flag, 514, 791 manipulator, 523, 792 showpoint format flag, 514, 791 manipulator, 523, 792 showpos format flag, 514, 791 manipulator, 523, 792
SIG_DFL, 771
SIG_ERR, 771
SIG_IGN, 771
SIGABRT, 769
SIGFPE, 769
SIGILL, 769
SIGINT, 770
Sign flag, 16 signal( ), 770-771 signed modifier, 15-16
SIGSEGV, 770
SIGTERM, 770 sin( ), 150, 743 sinh( ), 744 size( ), 636, 637 sizeof operator, 50, 131, 183-184 size_t data type, 50, 130, 215,
398, 700, 724, 762, 776 skipws format flag, 513, 791 manipulator, 523, 792 slice class, 917-919 slice_array class, 920 sort( ), 647, 652-653 algorithm, 856 sort_heap( ) algorithm, 856-857 splice( ), 647, 648 sprintf( ), 720 sqrt( ), 150, 744 sscanf( ), 720 sqrt( ), 150, 744 srand( ), 771
<sstream> header, 790 stable_partition( ) algorithm, 857 stable_sort( ) algorithm, 857
Stack and local variables, 20 and recursive routines, 154 stack container, 633, 813,
833-834 member functions, table of, 834
<stack> header, 633, 813
Standard C++, 4, 257, 267
Standard template library
(STL), 11, 256-257, 630-695 elements of, 630-634 general theory of operation,
634-635
Statements, 57-88 static storage class specifier,
28-30, 310 static_cast, 588 std namespace, 261, 269-270,
510, 592, 601-603 stdarg.h header file, 722
<stdbool.h> header, 266
_ _STDC_ _ predefined macro, 250 stderr standard stream, 232-233
<stdexcept> header, 926, 927-928 stdin standard stream, 232-234 stdio.h header file, 188,
214-215, 700 stdlib.h header file, 59, 759, 762 stdout standard stream, 232-234
Stepanov, Alexander, 256
Storage class specifiers, 25-31 str( ), 624, 806 strcat( ), 94-95, 685, 729 strchr( ), 94-95, 729 strcmp( ), 74, 94-95, 128, 730 strcoll( ), 730 strcpy( ), 94-95, 684, 685, 731 strcspn( ), 731
Stream(s) binary, 212, 213
C++, 510 for C++ array-based I/O,
619-623 for C++ file I/O, 540 classes, 510-512, 540,
618-619 flushing, 226-227 predefined C++, 512-513 redirecting standard, 232,
233-235, 512 standard C, 232-233 text, 212-213 streambuf class, 512, 790
<streambuf> header, 791 streambuf_type, 872 streamoff data type, 793 streampos data type, 793 streamsize data type, 548, 793 strerror( ), 731 strftime( ), 753-754
Stride, 918
String(s) as arrays, 90, 94-95 arrays of, 100-101 class, creation of custom,
936-961 classes, Standard C++, 94,
630, 683-695, 882-896 in console I/O, 192-194 constant, 33, 94, 126 in C file I/O, 222 limitations of null-terminated, 683-684 manipulation functions,
94-95 substring subtraction from,
936, 945-946 table, 126
1022
C + + : T h e C o m p l e t e R e f e r e n c e string class, 94, 630, 683-695,
882, 884 and containers, 693-695 dynamic aspect of, 687 member functions, 687-692 operators defined for, 685
<string> header, 684 string.h header file, 724 stringbuf class, 790 stringstream class, 790 stringstream( ), 806-807 strlen( ), 24, 79, 94-95, 731-732 strncat( ), 732 strncmp( ), 732 strncpy( ), 733
Stroustrup, Bjarne, 256, 267 strpbrk( ), 733 strrchr( ), 733 strspn( ), 734 strstr( ), 94-95, 734 strstream class, 619, 623, 625
<strstream> header, 618 strtod( ), 771-772 strtok( ), 734 strtol( ), 772 strtoul( ), 772-773 struct keyword, 162, 163, 295
Structure(s), 162-174 arrays of, 166 arrays and structures within, 173-174 assignments, 165-166 and classes, 293-295 declaration, 162-163,
164-165 members, accessing, 165,
171, 173 passing to functions,
167-169 pointers, 169-173 size of, determining, 183 variable, declaring, 163-164 strxfrm( ), 735 swap( ) algorithm, 857 swap_ranges( ) algorithm, 858 switch statement, 67-70 declaring variable within, 81 sync_with_stdio( ), 807 system( ), 773
Systems program, 9
T tan( ), 744 tanh( ), 744 tellg( ), 561, 808 tellp( ), 561, 808
Template function. See Generic function(s) template keyword, 460 template< > syntax, 465, 483
Templates, 460-485 advantages to using, 485 definition of, 460
See also Generic class;
Generic function(s) terminate( ), 489, 503-505 terminate_handler type, 504, 927
Ternary operator (?), 47-48, 63-66 this pointer, 315, 332-334,
386, 391
Thompson, Ken, 4 throw statement, 489-490,
502-503 throw( ) clause, 500
Time and date functions,
748-755
Time delay loops, 77 time.h header file, 748 time( ), 754-755
_ _TIME_ _ predefined macro, 250 time_t data type, 748 tm structure, 748
TMP_MAX, 721 tmpfile( ), 720-721 tmpnam( ), 721
Token, 969 tolower( ), 735 toupper( ), 735 towctrans( ), 778-779 transform( ) algorithm, 667,
673-674, 676-678, 858 true, 40, 58, 266
True and false in C and C++,
40, 58 trunc, 793 try statement, 488-493, 501-502
_ _try_cast keyword, 1002
Two’s complement, 16
Type checking and C++ pointers, 549
Type conversion and ambiguity in function overloading, 378-380 in assignments, 35-37 in expressions, 53-54 using unions for nonstandard, 178-179
Type promotion, 53 type_info class, 568, 931 typedef statement, 162, 184-185 typeid, 568-578, 926-927 using dynamic_cast to replace, 582-584
<typeinfo> header, 568, 931 typename keyword, 460,
484-485
_ _typeof keyword, 1002
Types. See Data types
U
ULONG_MAX, 773 unary_function class, 678,
873-874 unary_negate class, 875, 876 uncaught_exception( ), 505
#undef directive, 246-247 underflow_error exception, 928 unexpected( ), 500, 501,
503-504, 926 unexpected_handler type,
504, 927 ungetc( ), 721-722 union keyword, 177
Unions, 162, 176-179, 184 anonymous, 179, 296-297 and classes, 295-297 for nonstandard type conversions, 178-179 size of, determining, 184
I n d e x
1023 unique( ) algorithm, 858-859 unique_copy( ) algorithm,
858-859 unitbuf format flag, 514, 791 manipulator, 523, 792
UNIX, 4 unmanaged pragma, 1002
UnPred type, 632, 812 unsetf( ), 515-516, 808 unsigned modifier, 14-16 upper_bound( ) algorithm, 859 uppercase format flag, 514, 791 manipulator, 523, 792
#using preprocessor directive, 1002 using statement, 261, 270, 434,
437, 596-598
<utility> header, 632, 931
V va_arg( ), 773-774 va_end( ), 773-774 va_list type, 722, 774 va_start( ), 773-774 valarray class, 902-920 member functions, table of,
903-907 nonmember operator functions defined for, table of, 908-913 transcendental functions defined for, table of,
914-915
<valarray> header, 902
_ _value keyword, 1002
Variables, 17-23 automatic, 18 declaration vs.
definition of, 26 declaring, 17-18, 81-82 as formal parameters, 21 initializing, 31-32 instance, 292 member. See Member variables placement in memory, 133 pointer, 48-49, 115 reference. See Reference(s) register, 30-31 storage class specifiers for,
25-31 structure, 163-164
Variables, global, 7, 21-23 declarations, difference between C and C++, 626 and encapsulation, 315 extern used with, 25-27 static, 29-30, 598-599
Variables, local, 6-7, 18-20,
21, 22 declarations, differences between C and C++,
19-20, 264-265, 626 initializing, 20 static used with, 20, 28-29,
30, 139 vector container, 630, 633, 634,
635-645, 813, 834-837 member functions, table of,
637, 835-837
<vector> header, 633, 813 vfprintf( ), 722
Virtual functions, 444-458 and base-class references,
447-448 and class libraries, 458 hierarchical nature of,
450-453 and inheritance of virtual attribute, 448-450 and late binding, 458 overloading versus overriding and, 446-447 pure, 453-455 using, 455-458 virtual keyword, 440, 444, 445
Visual C++ compiler, 191 void data type, 14, 15, 153,
261, 626 volatile access modifier,
24-25, 609 vprintf( ), 722 vsprintf( ), 722
W wchar.h header file, 776
WCHAR_MAX, 776
WCHAR_MIN, 776 wchar_t data type, 14, 32, 513,
698, 776 wcstombs( ), 774 wctomb( ), 774 wctrans( ), 778-779 wctrans_t type, 776 wctype.h header file, 776 wctype( ), 776-778 wctype_t type, 776
WEOF macro, 776 werr, 513 what( ), 794, 926 while loop, 7, 77-79 declaring variable within, 81
Wide character(s), 511, 513, 545 functions, 776-784
I/O classes, 512, 789-790 width( ), 520, 521-522, 808-809 win, 513 wint_t type, 776 wlog, 513
Word alignment, 183 wout, 513 write( ), 548-551, 626, 809 ws manipulator, 523, 792 wstreampos type, 793 wstring class, 683, 862, 864
X
XOR bitwise operator (^), 43, 45 logical operation, 40-42
INTERNATIONAL CONTACT INFORMATION
AUSTRALIA
McGraw-Hill Book Company Australia Pty. Ltd.
TEL +61-2-9900-1800
FAX +61-2-9878-8881 http://www.mcgraw-hill.com.au
CANADA
McGraw-Hill Ryerson Ltd.
TEL +905-430-5000
FAX +905-430-5020 http://www.mcgraw-hill.ca
GREECE, MIDDLE EAST, & AFRICA
(Excluding South Africa)
McGraw-Hill Hellas
TEL +30-210-6560-990
TEL +30-210-6560-993
TEL +30-210-6560-994
FAX +30-210-6545-525
MEXICO (Also serving Latin America)
McGraw-Hill Interamericana Editores S.A. de C.V.
TEL +525-117-1583
FAX +525-117-1589 http://www.mcgraw-hill.com.mx
SINGAPORE (Serving Asia)
McGraw-Hill Book Company
TEL +65-863-1580
FAX +65-862-3354 http://www.mcgraw-hill.com.sg
SOUTH AFRICA
McGraw-Hill South Africa
TEL +27-11-622-7512
FAX +27-11-622-9045 [email protected]
SPAIN
McGraw-Hill/Interamericana de España, S.A.U.
TEL +34-91-180-3000
FAX +34-91-372-8513 http://www.mcgraw-hill.es
UNITED KINGDOM, NORTHERN,
EASTERN, & CENTRAL EUROPE
McGraw-Hill Education Europe
TEL +44-1-628-502500
FAX +44-1-628-770224 http://www.mcgraw-hill.co.uk
ALL OTHER INQUIRIES Contact:
Osborne/McGraw-Hill
TEL +1-510-549-6600
FAX +1-510-883-7600 http://www.osborne.com
Prenesi
Oglas