Operator Function Example scope resolution scope: : name

Similar documents
Contents. 2 Introduction to C++ Programming,

Absolute C++ Walter Savitch

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

Deitel Series Page How To Program Series

The Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Chapter 15 - C++ As A "Better C"

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.

C++ How To Program 10 th Edition. Table of Contents

Borland 105, 278, 361, 1135 Bounded array Branch instruction 7 break statement 170 BTree 873 Building a project 117 Built in data types 126

Tokens, Expressions and Control Structures

Short Notes of CS201

Introduction to C++ Systems Programming

CS201 - Introduction to Programming Glossary By

Chapters and Appendices F J are PDF documents posted online at the book s Companion Website, which is accessible from.

Lecture 21 Standard Template Library. A simple, but very limited, view of STL is the generality that using template functions provides.

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Problem Solving with C++

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Basic Types, Variables, Literals, Constants

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

CS3157: Advanced Programming. Outline

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers.

Variables. Data Types.

Introduction to Programming Using Java (98-388)

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

C++ Primer, Fifth Edition

Welcome to Teach Yourself Acknowledgments Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p.

Advanced C++ Programming Workshop (With C++11, C++14, C++17) & Design Patterns

I BSc(IT) [ Batch] Semester II Core: Object Oriented Programming With C plus plus - 212A Multiple Choice Questions.

Refinements to basic_string

Standard Library Reference

UNIT- 3 Introduction to C++

Interview Questions of C++

C++ (Non for C Programmer) (BT307) 40 Hours

CS201 Some Important Definitions

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Introduction to Programming

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

Streams - Object input and output in C++

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

Index COPYRIGHTED MATERIAL

Axivion Bauhaus Suite Technical Factsheet MISRA

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

C-LANGUAGE CURRICULAM

COEN244: Class & function templates

Practical C++ Programming

4 Strings and Streams. Testing.

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

Harmonizing Effects and Returns Elements in Clause 21

Contents. 1 Introduction to Computers, the Internet and the World Wide Web 1. 2 Introduction to C Programming 26

by Pearson Education, Inc. All Rights Reserved. 2

OBJECT ORIENTED PROGRAMMING USING C++

CERTIFICATE IN WEB PROGRAMMING

Programming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee

Instantiation of Template class

EEE145 Computer Programming

Dodatak D Standardna string klasa

Fundamentals of Programming

primer 2005/1/19 18:36 page 843 #865

std::cout << "Size of long = " << sizeof(long) << " bytes\n\n"; std::cout << "Size of char = " << sizeof(char) << " bytes\n";

Programming. C++ Basics

Assertions and Exceptions

Computer Science 306 Study Guide


VALLIAMMAI ENGINEERING COLLEGE

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

6.096 Introduction to C++ January (IAP) 2009


CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Axivion Bauhaus Suite Technical Factsheet AUTOSAR

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

PIC10B/1 Winter 2014 Exam I Study Guide

Unit 4 Basic Collections

Chapter 2. Procedural Programming

Index. Symbols. bit sequence, 27 ^ (exclusive OR) operator, 30 hexadecimal number, 27 left shift (<<) operator, 31 right shift (>>) operator, 32

Lecture 10. To use try, throw, and catch Constructors and destructors Standard exception hierarchy new failures

IBM i Version 7.2. Programming IBM Rational Development Studio for i ILE C/C++ Language Reference IBM SC

To use various types of iterators with the STL algorithms ( ). To use Boolean functions to specify criteria for STL algorithms ( 23.8).

Review of the C Programming Language for Principles of Operating Systems

Programming with Haiku

C++_ MARKS 40 MIN

Programming in C++ 4. The lexical basis of C++

Fundamental of Programming (C)

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Review of the C Programming Language

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING

SAURASHTRA UNIVERSITY

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

APPENDIX A : KEYWORDS... 2 APPENDIX B : OPERATORS... 3 APPENDIX C : OPERATOR PRECEDENCE... 4 APPENDIX D : ESCAPE SEQUENCES... 5

LEXICAL 2 CONVENTIONS

Major Language Changes, pt. 1

END TERM EXAMINATION

Ch. 12: Operator Overloading

Transcription:

Appendix A C++ Operators The relative precedence of the operators is shown, in decreasing order, in Table A.I where operators with the same precedence appear in the same "box". In the "example" column, exp stands for "expression", lvalue denotes an expression yielding an lvalue and explist stands for a comma-separated list of expressions. Operator Function Example scope resolution scope: : name. resolution in global scope : : scope: : name member selection cjassobject. membername -> member selection cjassobjectpointer. membername [] subscript pointer [exp 1 () function call exp (explist) typeid type identification typeid{type) typeid run-time type identifica- typeid (exp) tion dynamic_cast dynamic cast dynamic _cas t<type> (exp) static - cast static cast static _cast<type> (exp) reinterpret_cast reinterpret cast reinterpret_cast<type> (exp) const - cast const cast const _cast<type> (exp) type {) value construction double {'c') ++ post increment lvalue++ -- post decrement lvalue-- 265

266 APPENDIX A. C++ OPERATORS Operator Function Example sizeofo size of object or type sizeof(exp) ++ pre increment ++lvalue -- pre decrement --lvalue - bitwise complement - exp! logical not!exp - unary minus -exp + unary plus +exp & address of &lvalue * dereference *pointer new allocate and construct new (exp) type(explist) new [ ] allocate and construct ar- new [] (explist) type [ exp 1 ray delete destroy delete pointer delete [] destroy array delete [] pointer (type) cast (type conversion) (type) exp.* member selection classobject * ptrtomember ->* member selection classobjectptr - > * ptrtomember * multiplication exp * exp / division exp / exp % modulo (remainder) exp%exp + addition exp + exp - subtraction exp - exp «shift left, stream output exp«exp» shift right, stream input exp» exp < less than exp < exp <= less than or equal to exp <= exp > greater than exp > exp >= greater than or equal to exp >= exp -- equal to exp == exp!= not equal to exp! = exp & bitwise and exp & exp A bitwise xor exp A exp I bitwise or exp I exp && logical and exp && exp II logical or exp I I exp = assign lvalue = exp *= multiply and assign lvalue * = exp /= divide and assign lvalue / = exp %= modulo and assign lvalue %= exp += add and assign lvalue + = exp -= subtract and assign lvalue - = exp «= shift left and assign lvalue «= exp»= shift right and assign lvalue»= exp &= bitwise "and" and assign lvalue &= exp 1= bitwise "or" and assign lvalue I = exp = bitwise "xor" and assign lvalue = exp A? conditional expression exp?exp: exp throw throw expression throwexp I sequence expression exp, exp Table A.I: Precedence, in decreasing order, of operators.

AppendixB The String Class The string class is actually an instance of the more general basic_string class template which takes three template arguments. The CharT type specifies the underlying type of character; a basic_string represents a sequence of such CharT objects. The Trai t s type specifies a number of properties of the CharT type, e.g. the "end of string" character, CharT comparison and conversion operations, etc. The Alloc parameter specifies a class that provides memory management services for the allocation of basic_string objects. For the string class, the parameters are instantiated as shown below. typedef basic_string<char,chaltraits<char>,allocator<char> > string; typedef basic_string<wchar_t,char_traits<wchar_t>,allocator<wchar_t> > wstring; The allocator<char> type is an instance of the standard system-provided allocator class template (see e.g. [Str97], page 567). Wstring is the equivalent of string for "wide" characters (see Section 2.1). tempiate<typename CharT, typename Traits, typename Alloc> class basic_string { public: typedef Traits traits-type; typedef typename Traits::char_type value_type; typedef Alloc allocatoltype; typedef typename Alloc::size_type size_type; II size of string type static const size_type npos = static_cast<size_type>c-1); II maximum size of a string typedef typename Alloc::difference_type difference_type; typedef typename Alloc::reference reference; typedef typename AlJoc::consLreference conslreference; typedef typename Alloc::pointer pointer; typedef typename AlJoc::consLpointer conslpointer; 267

268 APPENDIX B. THE STRING CLASS / / defining iterator types makes a string a container to which stl algorithms can be applied typedef... iterator; typedef... consliterator; typedef... conslreverse_iterator; typedef... reverse_iterator; / / construction, destruction, assignment inline basic_stringo; explicit basilstring(const AlIoc&); / / new string contains s{pos].. s{max(pos+n,size()-l)] basic_string(const basic_string& s, size_type pos=o, size_type n=npos, const AlIoc& a=alioc()); / / new string contains s{o].. s{n-l] basic_string(const CharT* s, size_type n, const AlIoc& a = AlIoc()); / / new string contains s{o].. s[strlen(s)-l] basic_string(const CharT* s, const AlIoc& a = AlIoc()); / / new string consists of n copies of c basic_string(size_type n, CharT c, const AlIoc& a = AlIoc()); / / Inputlterator::valuLtype should be CharT template< class Inputlterator> basic_string(inputiterator begin, Inputlterator end, const AlIoc& a = AlIoc()); oasic_stringo; basic_string& operator=(const basic_string& str); basilstring& operator=(const CharT* s); basic_string& operator=(chart c); / / e.g. s = 'a' makes a string of size 1 / / iterators iterator begin(); consliterator begino const; iterator endo; consliterator endo const; reverse_iterator rbegino; conslreverse_iterator rbegino const; reverse_iterator rendo; conslreverse_iterator rendo const; / / size of string size_type sizeo const; size_type lengtho const { return sizeo; } size_type max_sizeo const; / / max size of string, depends on allocator void resize(size_type n, CharT c=chart()); / / resize to n by erasing at end or appending c's size_type capacityo const; / / available size without reallocation void reserve(size_type n = 0); / / ensure n <= capacity() void clearo { resize(o); } bool emptyo const { return sizeo == 0; } / / element access conslreference operator[] (size_type position) const; reference operator[ ](size_type position); conslreference at(size_type position) const; / / throw oulof-,ange exception if out of range reference at(size_type position); / / append basic_string& operator+=(const basic_string& str) { return append(str); } basic_string& operator+=(const CharT* s) { return append(s); } basic_string& operator+=(chart c) { return append(1,c); } basic_string& append(const basilstring& s); basic_string& append(const basic_string& s, size_type pos, size_type n); / / append sipos].. s{pos+n-l] basic_string& append(const CharT* s, size_type n); / / append s[o]..s{n-l] basic_string& append( const CharT * s); basic_string& append(size_type n, CharT c); / / append n c's template<class Inputlterator> / / value_type should be CharT

APPENDIX B. THE STRING CLASS 269 basic_string& append(inputlterator first, Inputlterator last); void push_back(chart c); II *this += c II assign basic_string& assign(const basic_string& s); basic_string& assign(const basic_string& s, size_type pos, size_type n); II assign s[posj.. s[pos+n-lj basic_string& assign(const CharT* s, size_type n); II assign s[oj.. s[n-l] basicstring& assign(const CharT* s); basic_string& assign(size_type n, CharT c); II assign c.. c (n c's) template<c1ass Inputlterator> basic_string& assign(inputiterator first, Inputlterator last); II replace *(this[posj.. this[pos+n-l]) by.. basic_string& replace(size_type pos, size_type n, const basic_string& s); II s basicstring& replace(size_ type pos, size_type n, const basic_string& s, size_type p2, size_type n2); II s[p2j..s[p2+n2-l] basic_string& replace(size_ type pos, size_type n, const CharT* s, size_type n2); II s[oj..s[n2-l] basic_string& replace(size_type pos, size_type n, const CharT* s); II s basic_string& replace(size_type pos, size_type n, size_type n2, CharT c); II n2 c's template<c1ass InputIterator> II replace *il.. *i2 by *j1.. *j2 basic_string& replace(iterator ii, iterator i2, InputIterator jl, InputIterator j2); basicstring& replace(iterator ii, iterator i2, const basic_string& s) { return replace(i I,i2,s.beginO,s.end()); } basic_string& replace(iterator ii, iterator i2, const CharT* s, size_type n) { return replace(i I,i2,s,s+n); } basic_string& replace(iterator ii, iterator i2, const CharT* s) { return replace(ii,i2,s,s+traitltype::length(s»; } basic_string& replace(iterator ii, iterator i2, size_type n, CharT c); II replace *il.. *i2 by n c's II insert void insert(iterator p, size_type n, CharT c) { replace(p, p, n, c); } template< class Inputlterator> void insert(iterator p, Inputlterator beg, Inputlterator end) { replace(p,p,beg,end); } basic_string& insert(size_type pos, const basic_string& s) { replace(begino+pos, begin()+pos, s.begino, s.endo); return *this; } basic_string& insert(size_type posl, const basic_string& s, size_type pos2, size_type n); basicstring& insert(size_type pos, const CharT* s, size_type n); basic_string& insert(size_type pos, const CharT* s); basicstring& insert(size_type pos, size_type n, CharT c); iterator insert(iterator p, CharT c = CharT()); II erase basic_string& erase(size_type pos = 0, size_type n = npos); iterator erase(iterator position); iterator erase(iterator first, iterator last); II retrieving a C string const CharT* cstro const; const CharT* datao const; II result may NOT be a C string II searching strings, return matching position or string: :npos if not found size_type find(const CharT* s, size_type pos, size_type n) const; size_type find(const basic_string& s, size_type pos = 0) const; size_type find(const CharT* s, size_type pos = 0) const; size_type find(chart c, size_type pos = 0) const; size_type rfind(const basicstring& s, size_type pos = npos) const; size_type rfind(const CharT* s, size_type pos, size_type n) const; size_type rfind(const CharT* s, size_type pos = npos) const; size_type rfind(chart c, size_type pos = npos) const;

270 APPENDIX B. THE STRING CLASS size_type find_firslof(const basic_string& str, size_type pos = 0) const; size_type find_firslof(const CharT* s, size_type pos, size_type n) const; size_type find_firslof(const CharT* s, size_type pos = 0) const; size_type find_firslof(chart c, size_type pos = 0) const; size_type find_laslof(const basic_string& s, size_type pos = npos) const; size_type find_laslof(const CharT* s, size_type pos, size_type n) const; size_type find_laslof(const CharT* s, size_type pos = npos) const; size_type find_laslof(chart c, size_type pos = npos) const; size_type find_firslnolof(const basic_string& s, size_type pos = 0) const; size_type find_firslnolof(const CharT* s, size_type pos, size_type n) const; size_type find_firslnolof(const CharT* s, size_type pos = 0) const; size_type find_firslnolof(chart c, size_type pos = 0) const; size_type find_laslnolof(const basic_string& str, size_type pos = npos) const; size_type find_laslnolof(const CharT* s, size_type pos, size_type n) const; size_type find_laslnolof(const CharT* s, size_type pos = npos) const; size_type find_laslnolof(chart c, size_type pos = npos) const; / / grab substring basic_string substr(size_type pos = 0, size_type n = npos) const; / / compare (lexicographic): compare(sl,s2»0 is sl>s2, <0 if sl<s2, ==0 else int compare(const basic_string& s) const; int compare(size_type pos, size_type n, const basilstring& s) const; int compare(size_type posl, size_type nl, const basic_string& s, size_type pos2, size_type n2) const; int comparee const CharT * s) const; int compare(size_type pos, size_type nl, const CharT* s, size_type n2 = npos) const; }; / / ordinary string functions / / operator+: concatenate intine basic_string<ch,tr,a> operator+(const basic_string<ch,tr,a>& Is, const basic_string<ch,tr,a>& rs); intine basilstring<ch,tr,a> operator+(const Ch* Is, const basic_string<ch,tr,a>& rs); inline basic_string<ch,tr,a> operator+(ch Is, const basic_string<ch,tr,a>& rs); intine basic_string<ch,tr,a> operator+(const basic_string<ch,tr,a>& Is, const Ch* rs); intine basic_string<ch,tr,a> operator+(const basic_string<ch,tr,a>& Is, Ch rs); / / operator = = intine boot operator==(const basic_string<ch,tr,a>& Is, const basic_string<ch,tr,a>& rs); intine boot operator==(const Ch* Is, const basic_string<ch,tr,a>& rs); intine boot operator==(const basic_string<ch,tr,a>& Is, const Ch* rs); / / operator!= inline boot operator!=(const basic_string<ch,tr,a>& Is, const basic_string<ch,tr,a>& rs); intine boot operator!=(const Ch* Is, const basic_string<ch,tr,a>& rs); inline boot operator!=(const basilstring<ch,tr,a>& Is, const Ch* rs); / / operator < intine boot operator«const basic_string<ch,tr,a>& Is, const basic_string<ch,tr,a>& rs);

APPENDIX B. THE STRING CLASS 271 inune bool operator«const basic_string<ch,tr,a>& Is, const Ch* rs); inune bool operator«const Ch* Is, const basic_string<ch,tr,a>& rs); / / operator > inune bool operator>(const basic_string<ch,tr,a>& Is, const basic_string<ch,tr,a>& rs); inune bool operator>(const basic_string<ch,tr,a>& Is, const Ch* rs); inune bool operator>(const Ch* Is, const basicstring<ch,tr,a>& rs); / / operator < = inune bool operator<=(const basicstring<ch,tr,a>& Is, const basic_string<ch,tr,a>& rs); inune bool operator<=(const basic_string<ch,tr,a>& Is, const Ch* rs); inune bool operator<=(const Ch* Is, const basic_string<ch,tr,a>& rs); / / operator > = inune bool operator>=(const basic_string<ch,tr,a>& Is, const basic_string<ch,tr,a>& rs); inune bool operator>=(const basic_string<ch,tr,a>& Is, const Ch* rs); inune bool operator>=(const Ch* Is, const basicstring<ch,tr,a>& rs); / / I/O basic_istream<ch,tr>& / / read a string, skipping white space operator> >(basic_istream<ch,tr>& is, basic_string<ch,tr,a>& s); basic_ostream<ch,tr>& operator< «basic_ostream<ch,tr>& os, const basic_string<ch,tr,a>& s); basic_istream<ch,tr> & getline(basic_istream<ch,tr>& is, basic_string<ch,tr,a>& str, Ch delim); inune basic_istream<ch,tr>& getline(basic_istream<ch,tr>& is, basic_string<ch,tr,a>& s);

Bibliography [Aus98] Matthew H. Austem. Generic Programming and the STL. Addison Wesley, 1998. [CHW98] J. Coplien, D. Hoffman, and D. Weiss. On commonality and variability in software engineering. IEEE Software, 15(6):37-45, NovemberlDecember 1998. [Cop99] J. Coplien. Multi-Paradigm Designfor C++. Addison-Wesley, 1999. [GHJV94] E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, 1994. [LL98] [Str97] Stanley B. Lippman and Josee Lajoie. C++ primer. Addison-Wesley,3rd edition, 1998. Bjame Stroustrup. The C++ Programming Language. Addison-Wesley, 3rd edition, 1997. [WBW89] R. Wirfs-Brock and B. Wilkerson. Object-oriented design: A responsibility-driven approach. Proceedings OOPSLA '89, ACM SIG PLAN Notices, 24(10):71-76, October 1989. 273

Index " 65.cc,12.cpp,12 #define, 14 #endif, 15 #ifdef,15 #ifndef,15 #include, 14-16 _,77 \',26 \\,26 \a,26 \b,26 \f, 26 \n,26 \r,26 \t,26 \v,26 (), 65,265,266,,43,266.C,12?, 44, 266 [], 65,265 &,89,266 &&,30,33,65,266 ->*,65,266 ->,65,115,265 &=,31,33,65,266 /=,31,33,65,266 -=,31,33,65,266 *=,31,33,65,266 1=,31,33,65,266 +=,31,33,65,266 %=,31,33,65,266 «=,31,33,65,266»=,31,33,65,266 ~=,31,33,65,266 =,31,33,65,266 &,29,33,65,266 -,29,33,65,68,266 1, 29, 33, 65, 266 --,31,33,65,66,142,265,266 /,29,33,65,266.,265 ==,29,33,65,266 >=,29,33,65,266 >,29,33,65,266 ++,31,33,65,66,142,265,266 <=,29,33,65,266 <,29,33,65,266 -,29,33,65,266!=,29,33,65,266!,30,33,65,266 11,30,33,65,266 +,29,33,65,266 %,29,33,65,266 ::,265 «,29,33,65,227,229,266»,29,33,65,230,231,266.*,266 *,29,33,65,115,266 ~,29,33,65,266 *,34?,40 abstract class, 191 abstract data type, 2, 51 abstraction, 6, 52, 246 criteria, 252 instance, 250 sources, 252 access specifier, 53, 127, 194,247 private, 53, 67 protected, 53, 222 275

276 INDEX public, 53 accumulate, 173, 254 adaptor, 153, 163, 178 for container, 163, 177, 195 for iterator, 179 reversejterator, 181 address, 1, 89 adjacenldifference, 173 adjacentjind, 165 ADT,51 advance, 148 algorithm, 119, 164 copy, 152 copying, 169 counting, 166 filling, 170 find, 165 finding subranges, 165 heap operations, 177 maximum, 168 minimum, 168 mutating, 169 non-mutating, 165 numeric, 173 partitioning, 172 permuting, 171 processing a range, 166 random sampling, 172 random shuffling, 172 range comparison, 167 range transformation, 169 removing elements, 170 replacing, 169 set operations, 176 sort, 174 sorted range operations, 175 swapping, 169 allocator, 267 and bitwise, 29 logical, 29, 30 architecture, 246 argument deduction, 120 arguments default,38 unspecified, 38 arithmetic type, 25, 27 conversion, 27 operation, 28 operator, 29 array, 32, 95 and inheritance, 187 assignment, 97 initialization, 97 multidimensional, 101 parameter, 99 template class, 124 vs. pointer, 98 ASCII,26 asm, 19 assert.h, 77 assignment and conversion, 28 and initialization, 83 compound, 31 operator, 4,31,65, 110 statement, 4 associative container, 152, 157, 163 auto, 19 auto_ptr, 134 automatic object, 104 backjnsertjterator, 179, 180 backjnserter, 179 bad_cast, 202, 214 bad_exception, 214 bad_typeid, 214 base class, 183 base object, 184 basic_filebuf, 234 basicjstream, 236 basicjfstream, 235 basicjos, 226 basicjostream, 218, 231 basicjstream, 218, 227 basicjstringstream, 237 basic_ofstream, 236 basic_ostream, 218, 230 basic_ostringstream, 237 basic_streambuf, 218, 220 basic_string, 267

INDEX 277 bidirectional iterator, 142 bidirectionauterator _tag, 145 binary...search, 175 bitwise and, 29 bitwise complement operator, 29 bitwise or, 29 bitwise xor, 29 bool, 19,26 conversion to, 28 literal,26 boolalpha, 232 boolean, 26 break,19 break statement, 48 built-in types, 25 C,187 C string, 32 call by address, 11, 92 by reference, 10, 68, 84 by value, 10, 30, 83, 208 destructor, 212 frame, 49 function, 7, 43, 104,265 inline,40 late binding, 188 operator, 130 overloaded, 41 result, 8 retum,47 target, 56, 75 main function, 17 stack, 9,49, 104,208 case, 19 in switch statement, 46 sensitive, 19 use, 259 cast bad, 202,214 C style, 32, 266 const, 19,88,94,265 cross, 201 down, 201 dynamic, 19,201,203,265 static, 19, 112, 138,235,236,265 up, 201 catch, 19, 206 cccp,14 char, 19, 26, 34 character zero, 32 class, 19,51,53 abstract, 191 base, 183 virtual, 195,219 constructor, 56 copy, 58 default, 58 derived, 183 constructor, 185 destructor, 68 friend,73 hierarchy, 199 member, 53 object, 69 static,74 virtual, 187 member function constant, 86 nested,72 object, 54 member, 69 polymorphic, 202 scope, 55 template, 123, 124 instance, 125 specialization, 131 virtual member function, 188 class object, 5 life, 71 class template, 123 friends, 126 nested,127 code object, 14 cohesion, 255 data, 255 functional, 255 temporal, 256 collaborator, 259 command line, 101

278 INDEX comments, 20 commonalities, 250 compilation, 13 compiler, 12 complex, 103 component, 247 composition, 258 compound assignment, 31 compound statement, 43 const, 19,34,83 conslcast, 19,88,94,265 constant expression, 46 member function, 86 name, 20 pointer, 92 constants, 2 constness logical,88 physical, 88 constructor, 32, 56, 59, 105 copy,58,66,110 default, 58, 84, 106 derived class, 185 explicit, 62 value, 32, 81 container, 152 adaptor, 153, 177 associative, 152 deque, 163 hash-iilap, 163 hash-iiluitimap, 163 hash-iilultiset, 163 hash_set, 163 list, 153 map, 157 multimap, 163 multiset, 163 sequence, 152 set, 161 slist, 163 vector, 155 container adaptor, 163 continue, 19 continue statement, 48 control coupling, 257 control flow, 43 statement, 43 conversion, 27, 42, 61 and inheritance, 186 and overloading, 42 arithmetic type, 27 array to pointer, 98 explicit, 62 function, 61 of 0 to pointer, 90 of an arithmetic expression, 28 to boo!, 28 to void*, 111 copy, 152, 169 copy algorithm, 152 copy constructor, 58, 66, 110 copy_backward, 169 count, 166 counuf,166 coupling, 256 control, 257 derived class, 258 global object, 257 parameter, 257 representational, 256 cpp, 14 CRC, 259 criteria for abstraction, 252 crosscast, 201 cstdarg,39 cstr2double, 245 cvs, 20 dangling pointer, 106 data abstraction, 247 data cohesion, 255 data member, 53, 54 static,74 data object, 1 dec, 232 declaration, 12 and definition, 12 constructor, 56 data member, 54 destructor, 68

INDEX 279 friend, 126, 150 function, 12,29,37,58,213 candidate, 42 function member, 55 header file, 15-17 main function, 101 member, 53 mutable, 88 parameter, 7 scope, 23 statement, 43 static data member, 74 syntax, 12 template parameter, 118 translation unit, 19 typedef,81 using, 23 variable, 12, 102 without definition, 67 decrement, 31, 33, 66,141,142,265 default,19 default arguments, 38 default constructor, 58, 106 default value, 32 definition, 12 class, 53 class object, 54 class template, 123 function, 6, 42 function template, 117 namespace, 22 object, 3 of ADTs, 53, 163 reference variable, 4 symbol,17 type, 15 variable, 3 delete, 19,65, 105, 106,266 overloading, 110, 113 delete[], 106, 110 denominator, 54 dependency, 247 inheritance, 248 interface, 248 deque, 163, 164 dereference, 90 derivation, 183 private, 259 derived class coupling, 258 design classes, 260 pattern, 261 process, 259 destructor, 68, 110 and exceptions, 212 call,212 derived class, 185 virtual, 192 difference_type, 146, 147 directive #define, 14 #endif,15 #ifdef,15 #ifndef,15 #include, 14 preprocessor, 14 using, 24 do, 19 documentation, 260 domain classes, 259 domain_error, 215 double, 3, 19,25 downcast, 201 dynamic_cast, 19,201,203,265 else, 19 encapsulation, 51, 52, 247 of pointer, 107 endl,233 ends, 233 enum,19 enumeration type, 32, 68, 80, 132, 223 environment, 8 equal,167 equalrange, 175 exception, 48,206,214 bad cast, 202, 214 exception handling, 205, 206 executable file, 17 exit, 39 explicit, 19,62

280 INDEX conversion, 62 export, 15 expression, 2, 3 constant, 46 function call, 7 new, 105 statement, 42 extendible, 243 extern, 19 factory method, 133, 185 false, 19,26 family, 243 file executable, 17 object, l3 filebuf, 234 fill,170 fill-il, 170 finalizing an object, 68 find, 165 find_end, 165 find_firslof, 165 findj.f, 165 first, 153 fixed,232 float, 19,26 floating point number, 25 flush,233 for, 19 for statement, 45 foleach, 166 formal parameter, 7 reference, 10 format flags, 223 forward iterator, 142 forwardj.terator_tag, 145 fprintf,39 frame, 9 framework, 222 free object, 105 friend, 19, 71, 73 of class template, 126 fronunsertj.terator, 180 fronunserter, 180 fstream, 235, 236 function, 6, 12 body, 7 call,7,43 result, 8, 48 constructor, 56 declaration, 12, 37 candidate, 42 default arguments, 38, 61 definition, 6, 7, 42 body, 42 scope, 21 inline, 40, 60 main, 101 member, 53, 55, 59 declaration, 55 overloading, 56 name, 20 object, 128, l30, 131, 166, 233, 254 overloading, 41 pointer to, 102 polymorphic, 200 pure virtual member, 191 signature, 37 template, 117, 118, 203, 248, 250 argument deduction, 120 overloading, 120, 148 specialization, 120, 122 type, 37 unspecified arguments, 38 virtual member, 187 implementation, 189 functional, l31 functional abstraction, 246 functional cohesion, 255 generate, 170 generatejl, 170 generic programming, 140 getline, 229, 267 global object, 104 global object coupling, 257 good programs, 241 goto, 19,48 handle, 91

INDEX 281 has-a, 258 hash-illap, 163 hash-illu1timap, 163 hash-illultiset, 163 hash_set, 163 header file, 15,247 heap, 105, 177 hex, 232 identifier, 19 if,19 operator, 40 statement, 9, 43 ifstream, 235 implementation, 51, 246 multiple inheritance, 196 virtual member function, 189 includes, 176 increment, 31,66,141,142,265 inheritance, 184 access control, 193 and arrays, 187 and conversion, 186 and scope, 185 dependency, 248 multiple, 195 polymorphism, 199 private, 194, 259 protected, 194 virtual, 195, 197,219 initialization, 3 of array, 97 vs. assignment, 83 inline, 19 inline function, 40, 60 innelproduct, 173 inplace-illerge, 175 input iterator, 142 inputiterator _tag, 145 instantiation of abstraction, 250 template, 119-121 int, 2, 19,25,27 integer hexadecimal constant, 25 literal, 25 octal constant, 25 type, 26 integral type, 27, 46 interface, 51, 246 interface dependency, 248 internal, 232 invalid...argument, 215 ios, 226 ios_base, 224 ios_base.h,232 iostream, 217, 231 library, 30, 34 is-a, 183, 199,258 islleap, 177 is_sorted, 174 istream, 227 istreamiterator, 149 istringstream, 237 iterator, 115, 140, 141, 145, 146 adaptor, 178, 179 bidirectional, 142 category, 148 forward, 142 input, 142 input stream, 149 insert, 178 istream, 149 ostream, 152 output, 142 output stream, 151 random access, 142 reverse, 181 stream, 149 traits, 146 types associated with, 143 iteratolcategory, 146, 147 iterator _traits, 147 itoa, 238 Java, 89, 185, 192 keyword, 19 late binding, 188, 189 left, 232 length_error, 215

282 INDEX lexicographicalcompare, 167 overloading, 56 library, 247 pure virtual, 191 C++ standard, 24 virtual, 188 iostream, 30, 34 object, 69, 105 life of a class object, 71 pointer, 103, 107,233 linker, 17 protected, 193 symbol,17 pure virtual, 191 list, 153, 164 selection, 91 literal static,74 bool,26 virtual, 187 constant, 25 memory, 134 hexadecimal integer, 25 leak,107 integer, 25 management, 104 octal integer, 25 merge, 175 string, 32 message, 56 local object, 49 min, 168 lifetime, 49 min_element, 168 local variable, 49 mismatch,167 static,49 mixin, 196 logic_error, 215, 216 module, 247 logical and, 29, 30 multidimensional array, 101 logical not, 30 multimap, 163 logical or, 30 multiple inheritance, 195 long, 19,25 implementation, 196 double, 25 multiset, 163 10weLbound, 175 mutable, 19,88 lvalue, 3, 65, 89, 265 returned by function, 11 namespace, 19,22 naming convention, 19 macro, 39 negative variability, 250 main function, 17, 101 nested class, 72 maintainability, 243 nested class template, 127 makelleap, 177 new, 19,65,68, 113,266 mangle, 75 overloading, 110, 113 manipulator, 225, 232 placement, 113 map, 157, 158,258 new operator, 105 max, 168 new[], 105, 110 max-element, 168 nexlpermutation, 171 memjun, 166, 167 noboolalpha, 232 memjunjef, 167 noshowbase, 232 member noshowpoint, 232 access, 53 noshowpos, 232 data, 53, 54 noskipws, 232 declaration, 53 not function, 53, 55, 59 logical,30 declaration, 55 nounitbuf,232

INDEX 283 nouppercase, 232 nth_element, 174 null pointer, 90, 93, 106 number floating point, 25 numerator, 54 numeric, 164, 173 object, 1 address, 89 automatic, 104 class, 5, 54, 56 code, 14, 18 constant, 83 data, 1 definition, 3 deletion, 106 finalization, 68 free, 105 function, 128, 130,233 global,104 initialization, 56 layout, 54 member, 105 owner, 105 persistence, 202 static, 104 object file, 13, 17,247 object-oriented programming, 199 observable, 261 observer, 261 observer pattern, 261 oct, 232 of stream, 236 operator, 19,28 " 43 ::,60?,40,44 =,65 --, 142 ++, 142 «0,229 «,227»,230,231 address of, 89 assignment, 4,31,65,110 bitwise and, 29 bitwise complement, 29 bitwise or, 29 bitwise xor, 29 decrement, 31 delete, 106 delete[], 106 forbidding, 67 function, 29, 63 if, 40, 44 increment, 31 logical and, 30 logical not, 30 logical or, 30 new, 105 on arithmetic type, 29 overloading, 29,63 precedence, 32,265 scope, 49, 60 scope resolution, 73 sequence, 43 shift left, 29 shift right, 29 static_cast, 112, 138 value constructor, 32,81 or bitwise, 29 logical,30 ordering strictly weak:, 174 ostream, 42,230 ostreamjterator, 151, 152 ostringstream, 192,237 oulolrange, 215 output stream, 30 output iterator, 142 outpuuterator_tag, 145 overflow, 218 overflow_error, 215 overloaded,30 overloading, 38, 41 ->, 115 =,65 --,66

284 INDEX ++,66 *, 115 delete, 11 0, 113 function template, 120 matching rules, 42 member function, 56 new, 110, 113 operator, 63 resolution, 121 override, 252 overriding, 185 owner object, 105 ownership of pointer, 134 pair, 153 parameter, 6 array, 99 control, 257 conversion, 61 coupling, 257 declaration, 7 default value, 38, 61 formal,7 reference, 10 of main function, 10 1 placement new, 114 reference, 83 template, 118, 131 type, 37,117 parametrized type, 125 partial specialization, 131 partialsort, 174 partialsort_copy, 174 partialsum, 173 partition, 172 pattern, 261 persistent objects, 202 placement new, 113, 114 pointer, 34, 89, 146, 147 arithmetic, 98 constant, 92 dereference, 90 difference_type, 147 encapsulation, 107 iteratolcategory, 147 iteratoltraits, 147 member, 103, 107 null,90,93,106 pointer, 147 reference, 147 smart, 115 this, 93 to function, 102 to member, 103, 233 to pointer, 91 value_type, 147 vs. array, 98 vs. reference, 92 polymorphic class, 202 function, 200 polymorphism, 117, 118, 199 poplleap, 177 precedence, 32, 265 precision, 224 preprocessor, 14 directive, 14 prev _permutation, 171 priority queue, 177 priority _queue, 163 private, 19,53, 183, 186 inheritance, 194 problem space, 252 program linking, 17 organization, 15 structure, 12 program specification, 241 programming generic, 137 object-oriented, 199 promotion, 28 protected, 19,53, 193 inheritance, 194 public, 19,53 pure virtual member function, 191 pushlleap, 177 queue, 163 priority, 177 quicksort, 122

INDEX 285 random access iterator, 142 random-'lccessjterator _tag, 145 random-sample, 172 random_shuffle, 172 range_error, 215 Rational, 76 red-black tree, 158, 161 refactoring, 260 reference, 146, 147 counting, 132 type, 4, 12,83 variable, 4 vs. pointer, 92 register, 19 reinterprelcast, 19, 265 relocate, 18 remove, 170 remove_copy, 170 remove_copy jf, 170 removejf, 170 replace, 169 replace_copy, 169 replace_copy jf, 169 replaceif, 169 representational coupling, 256 resolve, 17 return, 19 return statement, 7, 47 reverse, 171 reverse_copy, 171 reversejterator, 181, 182 right, 232 robust program, 241, 242 rotate, 171 rotate_copy, 171 rtti,201 run-time type identification, 201 runtime_error, 215 rvalue,3 scientific, 232 scope, 21 and inheritance, 185 class, 55 defined by compound statement, 43 function body, 42 nested,21 operator, 49, 60 resolution, 23, 55 resolution operator, 73 search,165 searchjl, 165 second,153 segmentation fault, 242 selection of member, 91 sentinel, 100 sequence container, 152 services, 259 set, 161 seldifference, 176 setintersection, 176 selsymmetric_difference, 176 selunion, 176 shift left operator, 29 shift right operator, 29 short, 19,25,27 showbase, 232 showpoint, 232 showpos, 232 side effects, 37 signature, 37 signatures, 41 signed,19 size_t, 111 sizeof, 19,31,33,111,114,189,266 skipws, 232 slist, 163 smart pointer, 115 software maintenance, 243 solution space, 252 sort, 174 sortlleap, 177 source code control system, 20 source file, 12, 247 sparse matrix, 159 specialization, 252 class template, 131 function template, 120, 122 partial, 131, 147 specification, 241

286 INDEX sstream, 237 stable_partition, 172 stable_sort, 174 stack,163 standard library, 138 statement, 3, 7, 42 assignment, 4 break,48 compound, 43 continue, 48 control flow, 43 declaration, 43 expression, 42 for, 45 function call, 43 goto, 48 if, 9, 43 return, 7, 47 switch,46 while, 44 static, 19 local variable, 49 member, 74 object, 104 static_cast, 19, 112, 138,235,236 static_cast, 265 std,24 stdarg.h, 39 stddef.h, 111 stdlib.h, 79 stream output, 30 streambuf, 219, 220 streams, 217 strictly weak ordering, 174 string, 32, 267 literal, 32 string literal, 97, 100 struct, 19, 127 subclass, 183 substitutability, 183,258 subtype, 183 superclass, 183 swap, 169 swap..ranges, 169 switch,19 switch statement, 46 symbol linker, 17 unresolved, 17 tab character, 38 target of a member function call, 56, 60 template, 2, 19, 117 class, 123, 124 friends, 126 nested, 127 partial specialization, 131 specialization, 131 function, 117, 118,248,250 argument deduction, 120 overloading, 120 specialization, 120, 122 instance, 119 instantiation, 119-121 parameter, 118 type parameter, 118 temporal cohesion, 256 terminate, 209, 212 this, 19,66,93 throw, 19,206,266 tied streams, 226 tilde, 68 traits, 146 iterator, 147 transform, 169, 254 translation unit, 12, 19 true, 19,26 try,19,206 try statement, 206 type, 2,12 ADT,51 arithmetic, 25, 27 conversion, 27 operator, 28 associated with iterator, 143 built-in, 25 constant, 83 constructor, 83 default value, 32

INDEX 287 enumeration, 32, 68, 80 integer, 26 integral, 27, 46, 80 name, 19 offunction,37 pointer member, 103 reference, 4 type constructor, 2, 83, 117 reference, 5 typedef, 19,81 typeid, 19,201,203,265 typeinfo, 201 typename, 19, 118, 145 UML,260 uncaught...exception, 213 underflow, 218 underflow_error, 215 underscore, 77 unicode, 26 union, 19 unique, 170 unique_copy, 170 unitbuf, 232 unresolved symbol, 17 unsigned, 19, 26 unsigned int, 26, 27 unsigned long, 26 unsigned short, 26, 27 unspecified number of arguments, 38 upcast, 201 uppelbound, 175 uppercase, 232 URL,258 use case, 259 user-defined conversion, 61 using, 19 declaration, 23 directive, 24 value, 2 constructor, 32, 105 default,32 value_type, 146, 147 variability, 250 negative, 250 variable, 2, 3, 12 declaration, 12 local,49 name, 20 reference, 4 static,49 vector, 101, 152, 155, 156, 164 virtual, 19, 188 base class, 198,219 destructor, 192 function table, 189 inheritance, 195, 197,219 member function, 188 void,7,19 void*, 111 volatile, 19 vptr, 189,202 vtbl,189 wchalt, 19, 26 wfilebuf, 234 wfstream, 236 while, 19 statement, 44 white space, 151,224 wide character, 26 width,224 wifstream, 235 wios, 226 wiostream, 231 wistream, 227 wistringstream, 237 wofstream, 236 wostream, 230 wostringstream, 237 wstreambuf, 220 wstring, 267 xor bitwise, 29 zero character, 32