ATour of C++ Third Edition
Madrid
Bjarne Stroustrup
Paris
Cover photo by: Marco Pregnolato (Unsplash.com: @marco_pregnolato).
Author photo courtesy of Bjarne Stroustrup.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The author and publisher have taken care in thepreparationofthisbook,but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at corpsales@pearsoned.com or (800) 382-3419.
For government sales inquiries, please contact governmentsales@pearsoned.com.
For questions about sales outside the U.S., please contact intlcs@pearson.com.
Visit us on the Web: informit.com/aw
Library of Congress Control Number: 2022938722
Copyright © 2023 by Pearson Education, Inc.
All rights reserved. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For informationregarding permissions, request forms and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearson.com/permissions.
This book was typeset in Times and Helvetica by the author.
ISBN-13: 978-0-13-681648-5
ISBN-10: 0-13-681648-7
Second digital release, April 2023
1.7
4.4Error-Handling
6.1
7.1
8ConceptsandGenericProgramming
12.6 unordered_map ............................................................................165
12.7
12.8
13Algorithms
13.1 Introduction .................................................................................173
13.2
13.3
13.4
13.5
13.6Parallel Algorithms .....................................................................
13.7
14Ranges
14.1
15PointersandContainers
15.1
15.4Alternatives
16Utilities
17.8Type
This page intentionally left blank
Preface
When you wish to instruct, be brief.
–Cicero
C++ feels like a new language. That is, I can express my ideas more clearly, more simply, and more directly today than I could in C++98 or C++11. Furthermore, the resulting programs are better checked by the compiler and run faster.
This book gives an overview of C++ as defined by C++20, the current ISO C++ standard, and implemented by the major C++ suppliers. In addition, it mentions a couple library components in current use, but not scheduled for inclusion into the standard until C++23.
Like other modern languages, C++ is large and there are a large number of libraries needed for effective use. This thin book aims to give an experienced programmer an idea of what constitutes modern C++. It covers most major language features and the major standard-library components. This book can be read in just a day or two but, obviously, there is much more to writing good C++ than can be learned in that amount of time. However, the aim here is not mastery, but to give an overview, to give key examples, and to help a programmer get started.
The assumption is that you have programmed before. If not, please consider reading a textbook, such as Programming: Principles and Practice Using C++ (Second edition) [Stroustrup,2014], before continuing here. Even if you have programmed before, the language you used or the applications you wrote may be very different from the style of C++ presented here.
Think of a sightseeing tour of a city, such as Copenhagen or New York. Injustafew hours, you are given a quick peek at the major attractions, told a few background stories, and given some suggestions about what to do next. You do not know the city after such a tour. You do not understand all you have seen and heard; some stories may sound strange or even implausible. You do not know how to navigate the formal and informal rules that govern life in the city. To really know a city, you have to live in it, often for years. However, with a bit of luck, you will have gained a bit of an overview, a notion of what is special about the city, and ideas of what might be of interest to you. Afterthetour, the real exploration can begin.
This tour presents the major C++ language features as they support programming styles, such as object-oriented and generic programming. It does not attempt to provide a detailed, reference-manual, feature-by-feature view of the language. In the best textbook tradition, I try to explain a feature before I use it, but that is not always possible and not everybody reads the text strictly sequentially. I assume some technical maturity from my readers. So, the reader is encouraged to use the cross references and the index.
Similarly, this tour presents the standard libraries in terms of examples, rather than exhaustively. The reader is encouraged to search out additional and supporting material as needed. There is far more to the C++ ecosystem than just the facilities offered by ISO standard (e.g., libraries, build systems, analysis tools, and development environments). Thereisanenormousamountofmaterial(of varying quality) available on the Web. Mostreaderswillfindusefultutorialandoverview videos from conferences such as CppCon and Meeting C++. For technical details of the language and library offered by the ISO C++ standard, I recommend [Cppreference]. For example, when I mention a standard-library function or class, its definition can easily be looked up, and by examining its documentation, many related facilities can be found.
This tour presents C++ as an integrated whole, rather than as a layer cake. Consequently, I rarely identify language features as present in C, C++98, or later ISO standards. Such information can be found in Chapter 19 (History and Compatibility). I focus on fundamentals and try to be brief, but I have not completely resisted the temptation to overrepresent novel features, such as modules (§3.2.2), concepts (§8.2), and coroutines (§18.6). Slightly favoring recent developments also seems to satisfy the curiosity of many readers who already know some older version of C++.
A programming language reference manual or standard simply states what can be done, but programmers are often more interested in learning how to use the language well. This aspect is partly addressed in the selection of topics covered, partly in the text, and specifically in the advice sections. MoreadviceaboutwhatconstitutesgoodmodernC++canbefoundintheC++CoreGuidelines [Stroustrup,2015]. The Core Guidelines can be a good source for further exploration of the ideas presented in this book. You may note a remarkable similarity of the advice formulation and even the numbering of advice between the Core Guidelines and this book. One reason is that the first edition of ATour of C++ was a major source of the initial Core Guidelines.
Acknowledgments
Thanks to all who helped complete and correct the earlier editions of ATour of C++, especially to the students in my ‘‘Design Using C++’’ course at Columbia University. ThankstoMorgan Stanley for giving me time to write this thirdedition. ThankstoChuckAllison,GuyDavidson, Stephen Dewhurst, Kate Gregory, Danny Kalev, Gor Nishanov, and J.C. van Winkel for reviewing the book and suggesting many improvements.
This book was set using troff by the author using macros originating from Brian Kernighan. Manhattan, New York Bjarne Stroustrup
The Basics
The first thing we do, let’s kill all the language lawyers.
–HenryVI,Part II
•Introduction
•Programs
Hello, World!
•Functions
•Types, Variables, and Arithmetic
Arithmetic; Initialization
•Scope and Lifetime
•Constants
•Pointers, Arrays, and References
The Null Pointer
•Tests
•Mapping to Hardware
Assignment; Initialization
•Advice
1.1 Introduction
This chapter informally presents the notation of C++, C++’s model of memory and computation, and the basic mechanisms for organizing code into a program. These are the language facilities supporting the styles most often seen in C and sometimes called procedural programming.
1.2 Programs
C++ is a compiled language. For a program to run, its source text has to be processed by a compiler, producing object files, which are combined by a linker yielding an executable program. A C++ program typically consists of many source code files (usually simply called source files).
source file 1
source file 2 compile compile object file 1 object file 2
link executable file
An executable program is created for a specific hardware/system combination; it is not portable, say, from an Android device to a Windows PC. When we talk about portability of C++ programs, we usually mean portability of source code; that is, the source code can be successfully compiled and run on a variety of systems.
The ISO C++ standard defines two kinds of entities:
• Core language features, such as built-in types (e.g., char and int) and loops (e.g., for-statements and while-statements)
• Standard-library components, such as containers (e.g., vector and map) and I/O operations (e.g., << and getline())
The standard-library components are perfectly ordinary C++ code provided by every C++ implementation. Thatis,theC++standardlibrarycanbeimplementedinC++itselfandis(withvery minor uses of machine code for things such as thread context switching). This implies that C++ is sufficiently expressive and efficient for the most demanding systems programming tasks.
C++ is a statically typed language. That is, the type of every entity (e.g., object, value, name, and expression) must be known to the compiler at its point of use. The type of an object determines the set of operations applicable to it and its layout in memory.
1.2.1 Hello,World!
The minimal C++ program is int main() { } // theminimalC++program
This defines a function called main, which takes no arguments and does nothing.
Curly braces, {}, express grouping in C++. Here, they indicate the start and end of the function body. Thedoubleslash, //, begins a comment that extends to the end of the line. A comment is for the human reader; the compiler ignores comments.
Every C++ program must have exactly one global function named main(). Theprogramstarts by executing that function. The int integer value returned by main(), if any, is the program’s return value to ‘‘the system.’’ Ifnovalue is returned, the system will receive a value indicating successful completion. Anonzerovalue from main() indicatesfailure. Notevery operating system and execution environment makes use of that return value: Linux/Unix-based environments do, but Windowsbased environments rarely do.
Typically, a program produces some output. Here is a program that writes Hello,World!:
import std;
int main()
{
std::cout << "Hello, World!\n"; }
The line importstd; instructsthecompilertomake the declarations of the standard library available. Without these declarations, the expression std::cout << "Hello, World!\n"
would make no sense. The operator << (‘‘put to’’) writes its second argument onto its first. In this case, the string literal "Hello,World!\n" iswrittenontothestandardoutputstream std::cout. Astring literal is a sequence of characters surrounded by double quotes. In a string literal, the backslash character \ followed by another character denotes a single ‘‘special character.’’ Inthiscase, \n isthe newline character, so that the characters written are Hello,World! followed by a newline.
The std:: specifiesthatthename cout istobefoundinthestandard-librarynamespace(§3.3).I usually leave out the std:: whendiscussingstandardfeatures;§3.3shows how to make names from a namespace visible without explicit qualification.
The import directive is new in C++20 and presenting all of the standard library as a module std is not yet standard. This will be explained in §3.2.2. If you have trouble with importstd;, try the old-fashioned and conventional
#include <iostream> // includethedeclarations for the I/O stream library
int main()
{
std::cout << "Hello, World!\n"; }
This will be explained in §3.2.1 and has worked on all C++ implementations since 1998 (§19.1.1). Essentially all executable code is placed in functions and called directly or indirectly from main(). For example:
import std;
// importthedeclarations for the standard library
using namespace std; // make names from std visible without std:: (§3.3)
double square(double x) // squareadouble-precision floating-point number
{ return x∗x;
}
void print_square(double x)
{ cout << "the square of " << x << " is " << square(x) << "\n"; }
int main()
{ print_square(1.234);// print:thesquareof1.234is1.52276
A ‘‘return type’’ void indicatesthatafunctiondoesnotreturnavalue.
1.3 Functions
The main way of getting something done in a C++ program is to call a function to do it. Defining a function is the way you specify how an operation is to be done. A function cannot be called unless it has been declared.
A function declaration gives the name of the function, the type of the value returned (if any), and the number and types of the arguments that must be supplied in a call. For example:
Elem∗ next_elem();// noargument;returnapointertoElem(anElem*) void exit(int); // intargument;returnnothing double sqrt(double);// double argument; return a double
In a function declaration, the return type comes before the name of the function and the argument types come after the name enclosed in parentheses.
The semantics of argument passing are identical to the semantics of initialization (§3.4.1). That is, argument types are checked and implicit argument type conversion takes place when necessary (§1.4). For example:
double s2 = sqrt(2); // callsqrt()withtheargumentdouble{2} double s3 = sqrt("three"); // error:sqrt()requiresanargumentoftypedouble
The value of such compile-time checking and type conversion should not be underestimated.
A function declaration may contain argument names. This can be a help to the reader of a program, but unless the declaration is also a function definition, the compiler simply ignores such names. For example:
double sqrt(double d); // returnthesquarerootofd double square(double);// returnthesquareoftheargument
The type of a function consists of its return type followed by the sequence of its argument types in parentheses. For example: double get(const vector<double>& vec, int index);// type:double(const vector<double>&,int)
A function can be a member of a class (§2.3, §5.2.1). For such a memberfunction, the name of its class is also part of the function type. For example: char& String::operator[](int index); // type:char&String::(int)
We want our code to be comprehensible because that is the first step on the way to maintainability. The first step to comprehensibility is to break computational tasks into meaningful chunks (represented as functions and classes) and name those. Such functions then provide the basic vocabulary of computation, just as the types (built-in and user-defined) provide the basic vocabulary of data.
The C++ standard algorithms (e.g., find, sort, and iota) provide a good start (Chapter 13). Next, we can compose functions representing common or specialized tasks into larger computations. The number of errors in code correlates strongly with the amount of code and the complexity of the code. Both problems can be addressed by using more and shorter functions. Using a function to do a specific task often saves us from writing a specific piece of code in the middle of other code; making it a function forces us to name the activity and document its dependencies. If we cannot find a suitable name, there is a high probability that we have a design problem.
If two functions are defined with the same name, but with different argument types, the compiler will choose the most appropriate function to invoke for each call. For example:
void print(int); // takes an integer argument
void print(double);// takes a floating-point argument void print(string); // takes a string argument
void user()
{ print(42); // callsprint(int) print(9.65); // callsprint(double) print("Barcelona");// callsprint(string)
}
If two alternative functions could be called, but neither is better than the other, the call is deemed ambiguous and the compiler gives an error. For example:
void print(int,double); void print(double,int);
void user2()
{ print(0,0);// error:ambiguous
}
Defining multiple functions with the same name is known as functionoverloading andisoneofthe essential parts of generic programming (§8.2). When a function is overloaded, each function of the same name should implement the same semantics. The print() functionsareanexample of this; each print() printsitsargument.
1.4 Types,Variables,andArithmetic
Every name and every expression has a type that determines the operations that may be performed on it. For example, the declaration int inch;
specifies that inch isoftype int; that is, inch isaninteger variable.
A declaration isastatementthatintroducesanentityintotheprogramandspecifiesitstype:
• A type definesasetofpossiblevalues and a set of operations (for an object).
• An object issomememorythatholdsavalue of some type.
• A value isasetofbitsinterpretedaccordingtoatype.
• A variable isanamedobject.
C++ offers a small zoo of fundamental types, but since I’m not a zoologist, I will not list them all. You can find them all in reference sources, such as the [Cppreference] on the Web. Examplesare:
bool // Boolean,possible values are true and false char // character, for example, 'a', 'z', and '9' int // integer, for example, -273, 42, and 1066
double// double-precision floating-point number, for example, -273.15, 3.14, and 6.626e-34 unsigned// non-negative integer, for example, 0, 1, and 999 (use for bitwise logical operations)
Each fundamental type corresponds directly to hardware facilities and has a fixed size that determines the range of values that can be stored in it:
bool: char: int: double: unsigned:
A char variable is of the natural size to hold a character on a given machine (typically an 8-bit byte), and the sizes of other types are multiples of the size of a char. Thesizeofatypeisimplementation-defined (i.e., it can vary among different machines) and can be obtained by the sizeof operator; for example, sizeof(char) equals 1 and sizeof(int) is often 4. Whenwewant a type of a specific size, we use a standard-library type alias, such as int32_t (§17.8).
Numbers can be floating-point or integers.
• Floating-point literals are recognized by a decimal point (e.g., 3.14) or by an exponent (e.g., 314e-2).
• Integer literals are by default decimal (e.g., 42 means forty-two). A 0b prefix indicates a binary (base 2) integer literal (e.g., 0b10101010). A 0x prefix indicates a hexadecimal (base 16) integer literal (e.g., 0xBAD12CE3). A 0 prefix indicates an octal (base 8) integer literal (e.g., 0334).
To make long literals more readable for humans, we can use a single quote (') as a digit separator For example, π isabout 3.14159'26535'89793'23846'26433'83279'50288 or if you prefer hexadecimal notation 0x1.921F'B544'42D1'8P+1.
1.4.1 Arithmetic
The arithmetic operators can be used for appropriate combinations of the fundamental types:
x+y// plus +x// unaryplus x-y// minus -x// unaryminus
x∗y// multiply x/y// divide x%y// remainder(modulus)for integers
So can the comparison operators:
x==y// equal x!=y// notequal x<y// lessthan x>y// greater than x<=y// lessthanorequal x>=y// greater than or equal
Furthermore, logical operators are provided:
x&y// bitwiseand x|y// bitwiseor xˆy// bitwiseexclusive or ˜x// bitwisecomplement x&&y// logicaland x||y// logicalor !x// logicalnot(negation)
A bitwise logical operator yields a result of the operand type for which the operation has been performed on each bit. The logical operators && and || simplyreturn true or false dependingonthe values of their operands.
In assignments and in arithmetic operations, C++ performs all meaningful conversions between the basic types so that they can be mixed freely: void some_function() // functionthatdoesn’treturnavalue { double d = 2.2; // initialize floating-point number int i = 7; // initialize integer d = d+i; // assignsumtod i = d∗i; // assignproducttoi;beware: truncating the double d*i to an int }
The conversions used in expressions are called theusualarithmeticconversions andaimtoensure that expressions are computed at the highest precision of their operands. For example, an addition of a double andan int iscalculatedusingdouble-precisionfloating-pointarithmetic.
Note that = istheassignmentoperatorand == testsequality.
In addition to the conventional arithmetic and logical operators, C++ offers more specific operations for modifying a variable:
x+=y// x=x+y
++x// increment:x=x+1
x-=y// x=x-y
--x// decrement:x=x-1
x
∗=y// scaling:x=x*y
x/=y// scaling:x=x/y
x%=y// x=x%y
These operators are concise, convenient, and very frequently used.
The order of evaluation is left-to right for x.y, x->y, x(y), x[y], x<<y, x>>y, x&&y, and x||y. For assignments (e.g., x+=y), the order is right-to-left. For historical reasons realated to optimization, the order of evaluation of other expressions (e.g., f(x)+g(y)) and of function arguments (e.g., h(f(x),g(y))) is unfortunately unspecified.
1.4.2 Initialization
Before an object can be used, it must be given a value. C++offers a variety of notations for expressing initialization, such as the = usedabove, and a universal form based on curly-bracedelimited initializer lists:
double d1 = 2.3; // initialize d1 to 2.3 double d2 {2.3}; // initialize d2 to 2.3 double d3 = {2.3}; // initialize d3 to 2.3 (the = is optional with { ... })
complex<double> z = 1; // acomplex number with double-precision floating-point scalars complex<double> z2 {d1,d2}; complex<double> z3 = {d1,d2}; // the=isoptionalwith{...}
vector<int> v {1, 2, 3, 4, 5, 6}; // avector of ints
The = formistraditionalanddatesbacktoC,but if in doubt, use the general {}-list form. If nothing else, it saves you from conversions that lose information:
int i1 = 7.8; // i1becomes7(surprise?)
int i2 {7.8}; // error:floating-pointtointegerconversion
Unfortunately, conversions that lose information, narrowing conversions, such as double to int and int to char, are allowed and implicitly applied when you use = (but not when you use {}). Theproblems caused by implicit narrowing conversions are a price paid for C compatibility (§19.3).
A constant (§1.6) cannot be left uninitialized and a variable should only be left uninitialized in extremely rare circumstances. Don’t introduce a name until you have a suitable value for it. Userdefined types (such as string, vector, Matrix, Motor_controller, and Orc_warrior) can be defined to be implicitly initialized (§5.2.1).
When defining a variable, you don’t need to state its type explicitly when the type can be deduced from the initializer:
auto b = true; // abool
auto ch = 'x'; // achar
auto i = 123; // anint
auto d = 1.2; // adouble auto z = sqrt(y); // zhasthetypeofwhatever sqrt(y) returns auto bb {true}; // bb is a bool
With auto, we tend to use the = becausethereisnopotentiallytroublesometypeconversion involved, but if you prefer to use {} initializationconsistently, you can do that instead.
We use auto wherewedon’t have a specific reason to mention the type explicitly. ‘‘Specific reasons’’ include:
• The definition is in a large scope where we want to make the type clearly visible to readers of our code.
•The type of the initializer isn’t obvious.
•We want to be explicit about a variable’s range or precision (e.g., double ratherthan float). Using auto, we avoid redundancy and writing long type names. This is especially important in generic programming where the exact type of an object can be hard for the programmer to know and the type names can be quite long (§13.2).
1.5 ScopeandLifetime
A declaration introduces its name into a scope:
• Local scope: A name declared in a function (§1.3) or lambda (§7.3.2) is called a localname Its scope extends from its point of declaration to the end of the block in which its declaration occurs. A block isdelimitedbya {} pair. Functionargument names are considered local names.
• Class scope: A name is called a membername (ora classmembername) if it is defined in a class (§2.2, §2.3, Chapter 5), outside any function (§1.3), lambda (§7.3.2), or enum class (§2.4). Itsscopeextends from the opening { ofitsenclosingdeclarationtothematching }.
• Namespace scope: A name is called a namespacemembername ifitisdefinedinanamespace (§3.3) outside any function, lambda (§7.3.2), class (§2.2, §2.3, Chapter 5), or enum class (§2.4).Itsscopeextends from the point of declaration to the end of its namespace. A name not declared inside any other construct is called a globalname andissaidtobeinthe global namespace
In addition, we can have objects without names, such as temporaries and objects created using new (§5.2.2).For example:
vector<int> vec; // vec is global (a global vector of integers)
void fct(int arg)// fctisglobal(namesaglobalfunction) // argislocal(namesanintegerargument)
{ string motto {"Who dares wins"}; // mottoislocal auto p = new Record{"Hume"};// ppointstoanunnamedRecord(createdby new) // ... }
struct Record { string name; // nameisamemberofRecord(astringmember) // };
An object must be constructed (initialized) before it is used and will be destroyed at the end of its scope. For a namespace object the point of destruction is the end of the program. For a member, the point of destruction is determined by the point of destruction of the object of which it is a member. Anobjectcreatedby new ‘‘lives’’ until destroyed by delete (§5.2.2).
1.6 Constants
C++ supports two notions of immutability (anobjectwithanunchangeablestate):
• const: meaning roughly ‘‘I promise not to change this value.’’ Thisisusedprimarilyto specify interfaces so that data can be passed to functions using pointers and references without fear of it being modified. The compiler enforces the promise made by const. Thevalue of a const maybecalculatedatruntime.
• constexpr: meaning roughly ‘‘to be evaluated at compile time.’’ Thisisusedprimarilyto specify constants, to allow placement of data in read-only memory (where it is unlikely to be corrupted), and for performance. The value of a constexpr mustbecalculatedbythe compiler.
For example:
constexpr int dmv = 17; // dmvisanamedconstant int var = 17; // var is not a constant const double sqv = sqrt(var); // sqvisanamedconstant,possibly computed at run time
double sum(const vector<double>&);// sumwillnotmodifyitsargument(§1.7)
vector<double> v {1.2, 3.4, 4.5}; // visnotaconstant const double s1 = sum(v); // OK:sum(v)isevaluated at run time constexpr double s2 = sum(v); // error:sum(v)isnotaconstantexpression
For a function to be usable in a constantexpression, that is, in an expression that will be evaluated by the compiler, it must be defined constexpr or consteval. For example:
constexpr double square(double x) { return x∗x; }
constexpr double max1 = 1.4∗square(17);// OK:1.4*square(17)isaconstantexpression constexpr double max2 = 1.4∗square(var);// error:var is not a constant, so square(var) is not a constant const double max3 = 1.4∗square(var);// OK:may be evaluated at run time
A constexpr functioncanbeusedfornon-constantarguments, but when that is done the result is not a constant expression. We allow a constexpr functiontobecalledwithnon-constant-expression arguments in contexts that do not require constant expressions. Thatway, we don’t have to define essentially the same function twice: once for constant expressions and once for variables. Whenwe want a function to be used only for evaluation at compile time, we declare it consteval ratherthan constexpr. For example:
consteval double square2(double x) { return x∗x; }
constexpr double max1 = 1.4∗square2(17);// OK:1.4*square2(17)isaconstantexpression const double max3 = 1.4∗square2(var); // error:var is not a constant
Functions declared constexpr or consteval are C++’s version of the notion of pure functions. They cannot have side effects and can only use information passed to them as arguments. Inparticular, they cannot modify non-local variables, but they can have loops and use their own local variables. For example:
constexpr double nth(double x, int n) // assume0<=n { double res = 1; int i = 0; while (i<n) { // while-loop:dowhiletheconditionistrue(§1.7.1) res ∗= x; ++i; } return res; }
In a few places, constant expressions are required by language rules (e.g., array bounds (§1.7), case labels (§1.8), template value arguments (§7.2), and constants declared using constexpr). Inother cases, compile-time evaluation is important for performance. Independent of performance issues, the notion of immutability (an object with an unchangeable state) is an important design concern.
1.7 Pointers,Arrays,andReferences
The most fundamental collection of data is a contiguously allocated sequence of elements of the same type, called an array. Thisisbasicallywhatthehardware offers. Anarrayofelementsof type char can be declared like this:
char v[6]; // array of 6 characters
Similarly, a pointer can be declared like this:
char∗ p; // pointertocharacter
In declarations, [ ] means ‘‘array of’’ and ∗ means‘‘pointer to.’’ Allarrayshave 0 as their lower bound, so v has six elements, v[0] to v[5]. Thesizeofanarraymustbeaconstantexpression (§1.6). A pointer variable can hold the address of an object of the appropriate type:
char∗ p=&v[3];// ppointstov’s fourth element
char x = ∗p;// *pistheobjectthatppointsto
In an expression, prefix unary ∗ means‘‘contents of’’ and prefix unary & means ‘‘address of.’’ We can represent that graphically like this:
p: v:
0:1:2:3:4:5:
Consider printing the elements of an array: void print()
{ int v1[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for (auto i=0; i!=10; ++i) // printelements cout << v[i] << '\n'; // }
This for-statement can be read as ‘‘set i tozero;while i isnot 10, print the ith element and increment i.’’ C++alsooffers a simpler for-statement, called a range-for-statement, for loops that traverse a sequence in the simplest way:
void print2()
{ int v[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for (auto x : v) // for each x in v cout << x << '\n';
for (auto x : {10, 21, 32, 43, 54, 65}) // for each integer in the list cout << x << '\n'; // }
The first range-for-statement can be read as ‘‘for every element of v, from the first to the last, place a copy in x andprintit.’’ Notethatwedon’t have to specify an array bound when we initialize it with a list. The range-for-statement can be used for any sequence of elements (§13.1).
If we didn’t want to copy the values from v intothevariable x, but rather just have x refertoan element, we could write: void increment()
{ int v[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for (auto& x : v) // add1toeachxinv ++x; // }
In a declaration, the unary suffix & means‘‘reference to.’’ Areferenceissimilartoapointer, except that you don’t need to use a prefix ∗ toaccessthevalue referred to by the reference. Also, a
reference cannot be made to refer to a different object after its initialization.
References are particularly useful for specifying function arguments. For example:
void sort(vector<double>& v); // sortv(visavector of doubles)
By using a reference, we ensure that for a call sort(my_vec), we do not copy my_vec. Therefore,it really is my_vec thatissortedandnotacopy of it.
When we don’t want to modify an argument but still don’t want the cost of copying, we use a const reference(§1.6);thatis,areferencetoa const. For example:
double sum(const vector<double>&)
Functions taking const referencesarevery common.
When used in declarations, operators (such as &, ∗, and []) are called declarator operators:
T a[n] // T[n]:aisanarray of n Ts
T∗ p// T*:pisapointertoT
T& r // T&:risareference to T
T f(A) // T(A):fisafunctiontakinganargumentoftypeAreturningaresultoftypeT
1.7.1 TheNullPointer
We try to ensure that a pointer always points to an object so that dereferencing it is valid. Whenwe don’t have an object to point to or if we need to represent the notion of ‘‘no object available’’ (e.g., for an end of a list), we give the pointer the value nullptr (‘‘the null pointer’’). Thereisonlyone nullptr sharedbyallpointertypes:
double∗ pd=nullptr;
Link<Record>∗ lst=nullptr;// pointertoaLinktoaRecord int x = nullptr; // error:nullptr is a pointer not an integer
It is often wise to check that a pointer argument actually points to something: int count_x(const char∗ p,char x) // countthenumber of occurrences of x in p[] // pisassumedtopointtoazero-terminated array of char (or to nothing)
{ if (p==nullptr) return 0; int count = 0; for (; ∗p!=0; ++p) if (∗p==x) ++count; return count; }
We can advance a pointer to point to the next element of an array using ++ andalsoleave out the initializer in a for-statement if we don’t need it.
The definition of count_x() assumesthatthe char∗ isa C-stylestring, that is, that the pointer points to a zero-terminated array of char. Thecharactersinastringliteralareimmutable,sotohandle count_x("Hello!"), I declared count_x() a constchar∗ argument.
In older code, 0 or NULL istypicallyusedinsteadof nullptr. However, using nullptr eliminates potential confusion between integers (such as 0 or NULL) and pointers (such as nullptr).
In the count_x() example, we are not using the initializer part of the for-statement, so we can use the simpler while-statement:
int count_x(const char∗ p,char x) // countthenumber of occurrences of x in p[] // pisassumedtopointtoazero-terminated array of char (or to nothing)
{ if (p==nullptr) return 0; int count = 0; while (∗p) { if (∗p==x) ++count; ++p; } return count;
}
The while-statement executes until its condition becomes false.
A test of a numeric value (e.g., while(∗p) in count_x()) is equivalent to comparing the value to 0 (e.g., while(∗p!=0)). Atestofapointervalue (e.g., if(p)) is equivalent to comparing the value to nullptr (e.g., if(p!=nullptr)).
There is no ‘‘null reference.’’ Areferencemustrefertoavalid object (and implementations assume that it does). There are obscure and clever ways to violate that rule; don’t do that.
1.8 Tests
C++ provides a conventional set of statements for expressing selection and looping, such as if-statements, switch-statements, while-loops, and for-loops. For example, here is a simple function that prompts the user and returns a Boolean indicating the response: bool accept()
{ cout << "Do you want to proceed (y or n)?\n"; // writequestion char answer = 0; // initialize to a value that will not appear on input cin >> answer; // readanswer if (answer == 'y') return true; return false; }
To match the << outputoperator(‘‘put to’’), the >> operator(‘‘get from’’) is used for input; cin is the standard input stream (Chapter 11). The type of the right-hand operand of >> determineswhat input is accepted, and its right-hand operand is the target of the input operation. The \n characterat the end of the output string represents a newline (§1.2.1).
Note that the definition of answer appearswhereitisneeded(andnotbeforethat).Adeclaration can appear anywhere a statement can.
The example could be improved by taking an n (for‘‘no’’) answer into account: bool accept2()
{ cout << "Do you want to proceed (y or n)?\n"; // writequestion char answer = 0; // initialize to a value that will not appear on input cin >> answer; // readanswer
switch (answer) { case 'y': return true; case 'n': return false; default:
cout << "I'll take that for a no.\n"; return false; } }
A switch-statement tests a value against a set of constants. Those constants, called case-labels, must be distinct, and if the value tested does not match any of them, the default ischosen.Ifthe value doesn’t match any case-label and no default isprovided, no action is taken.
We don’t have to exit a case byreturningfromthefunctionthatcontainsits switch-statement. Often, we just want to continue execution with the statement following the switch-statement. We can do that using a break statement.Asanexample, consider an overly clever, yet primitive, parser for a trivial command video game: void action()
{ while (true) { cout << "enter action:\n"; // requestaction string act; cin >> act; // readcharacters into a string Point delta {0,0}; // Point holds an {x,y} pair for (char ch : act) { switch (ch) { case 'u': // up case 'n': // north ++delta.y; break; case 'r': // right case 'e': // east ++delta.x; break; // ...moreactions...
default: cout << "I freeze!\n"; } move(current+delta∗scale); update_display(); } } }
Like a for-statement (§1.7), an if-statement can introduce a variable and test it. For example: void do_something(vector<int>& v)
{ if (auto n = v.size(); n!=0) { // ...we get here if n!=0 ...
} // }
Here, the integer n isdefinedforusewithinthe if-statement, initialized with v.size(), and immediately tested by the n!=0 conditionafterthesemicolon.Anamedeclaredinaconditionisinscope on both branches of the if-statement.
As with the for-statement, the purpose of declaring a name in the condition of an if-statement is to keep the scope of the variable limited to improve readability and minimize errors.
The most common case is testing a variable against 0 (orthe nullptr). To do that, simply leave out the explicit mention of the condition. For example:
void do_something(vector<int>& v)
{ if (auto n = v.size()) { // ...we get here if n!=0 ...
} // }
Prefer to use this terser and simpler form when you can.
1.9 MappingtoHardware
C++ offers a direct mapping to hardware. Whenyouuseoneofthefundamentaloperations,the implementation is what the hardware offers, typically a single machine operation. For example, adding two ints, x+y executes an integer add machine instruction.
A C++ implementation sees a machine’s memory as a sequence of memory locations into which it can place (typed) objects and address them using pointers:
Another random document with no related content on Scribd:
Marquis of Dorset
Sir Robert Brackenbury
Earl of Oxford
Sir Thomas Lovel
Sir William Kingston
Sir John Gage
Lord Clinton[9]
Sir Edward Bray
Lord Howard of Walden
During reigns of Henry VIII. and Edward VI.
Lord Coltington 1640
General Sir Thomas Fairfax 1647
Sir John Robinson 1660
James, Earl of Northampton 1678
Lord Allington 1680
George, Lord Dartmouth 1684
Lord Lucas 1688
Charles, Earl of Carlisle 1715
Henry, Earl of Lincoln 1724
Charles, Duke of Bolton 1724
Henry, Viscount Lonsdale 1726
Montague, Earl of Abingdon
Algernon, Earl of Essex
Richard, Earl of Rivers
George, Earl of Northampton
John, Earl of Leicester 1731
Charles, Lord Cornwallis 1741
Lord George Lennox
Marquis Cornwallis 1785
Francis, Marquis of Hastings 1806
Arthur, Duke of Wellington 1826
Viscount Combermere 1852
Sir John Fox Burgoyne 1865
Sir George Pollock 1871
Sir William Gomm 1872
Sir Charles Yorke 1875
Sir F. Fenwick Williams 1881
General Sir R. C. Dacres 1881
Lord Napier of Magdala 1886
General Sir Daniel Lysons 1890
Sir Frederick C. Stephenson 1898
INDEX
Abel, Dr, execution of, i. 159
Abergavenny, Lord, i. 131
Albert, Prince, i. 58, 59, 60; ii. 171
Alençon, Duke d’, i. 63
Allen, Cardinal, i. 213
Andrews, Colonel Eusebius, execution of, ii. 49
Anne Boleyn, i. 35, 39; State visit to the Tower, 131; coronation, 132; arrest, 143, 144; trial, 146; execution, 149
Anne of Cleves, i. 157
Apsley, Sir Allen, i. 41 and n., 42, 112
Arden, John, i. 50
Armagh, Archbishop of, murder of, i. 34
Armour in the White Tower, i. 64–73
Armoury, the, destroyed by fire, ii. 142–144
Arnold’s Chronicles, quoted, i. 117
Arques Castle, i. 61
Artillery at the Tower, i. 73
Arundel, Sir Thomas, execution of, i. 179, 180
Arundel, Philip Howard, Earl of, i. 31, 32, 214
Arundel, Richard Fitzalan, Earl of, arrest of, i. 95; execution of, 96
Arundel, Earl of, quarrel with Lord Spencer, ii. 27
Arundel, Humphrey, i. 180
Aske, Robert, i. 151
Askew, Anne, story of, i. 162–164
Athol, Earl of, i. 85, 86
Atterbury, Bishop, ii. 112
Audley, Mervin, Lord, execution of, ii. 32
Axe, the processional, i. 12, 25, 26, 70, 73; ii. 133
Axten, Colonel, execution of, ii. 58
Babington, Anthony, i. 215
Bacon, Francis, i. 48; imprisonment of, ii. 27
Badlesmere, Lady, i. 87
Bagot, Sir Francis, execution of, i. 151
Bailly, Charles, i. 33, 209
Balfour, Sir William, ii. 33, 37, 38
Baliol, King, i. 85
Ballard, trial and execution of, i. 215
Ballium Wall, the, i. 13, 14, 43, 44, 46, 51; restoration of, ii. 169
Balmerino, Lord, i. 40; ii. 116, 117; trial of, 118–120; execution of, 121–125
Banqueting Hall, i. 57; explosion in, ii. 145
Barkstead, Colonel, execution of, ii. 61
Barlow, Lucy, ii. 51, 52
Barnes, Dr Robert, execution of, i. 159
Barracks, the, ii. 145
Bathurst, Earl, i. 42
Battista, Giovanni, i. 46, 47
Beauchamp Tower, the, i. 14, 29–34, 44; ii. 94; restoration of, 169
Becket, Thomas à, i. 81, 83
Bedingfield, Sir Henry, i. 200
Bedingfield, Sir Thomas, ii. 42
Bell, Mr Doyne, i. 35, 36, 39
Bell, Dr, i. 127
Bell Tower, the, i. 14, 28, 29
Berkeley, Sir Maurice, i. 197
Besant, Sir Walter, quoted, i. 2, 6
Birch, Mr G. H., i. 2 n., 44 n., 61; ii. 93, 114 n.
Birds at the Tower, i. 74
Biron, Duke de, i. 228
Bishops, the Seven, ii. 86, 87
Block, the, i. 70; ii. 133
Blood, Colonel, i. 19, 42, 45; ii. 67–71
Bloody Tower, the, i. 12, 13, 17, 20, 21, 22; ii. 94; restoration of, 169, 175, 176
Blount, Sir Michael, i. 41, 217
Blount, Sir Richard, i. 41
Blunt, Sir Christopher, execution of, i. 229
Board of Ordinance, the, i. 68
Bonner, Bishop, i. 163, 201
Bowyer Tower, the, i. 45; part destroyed by fire, ii. 144
Brackenbury, Sir Robert, i. 116
Brass Mount Battery, i. 52
Brick Tower, the, i. 45
Bridges, the four, i. 9
Bridges, Sir John, i. 192, 193
Britton and Brayley, quoted, i. 44, 46, 64, 67
Broad Arrow Tower, the, i. 6, 46; restoration of, ii. 169
Brooke, Duke, ii. 6, 7
Brooke, George, ii. 2; execution of, 5
Brooke, William, ii. 7
Brown, Sir Anthony, i. 169, 177, 192
Brown, Horatio F., ii. 1 n.
Bruce, David, i. 87, 88
Buckingham, Edward Bohun, Duke of, i. 127, trial and execution of, 128–130
Buckingham, George Villiers, Duke of, bribed by Raleigh, ii. 8, 20; assassinated, 31
Buckingham, George Villiers, 2nd Duke of, five times imprisoned in the Tower, ii. 62
Bulwark, the, i. 9, 112
Bulwer, Sir John, execution of, i. 151
Bulwer, Lady, burnt at Smithfield, i. 151
Burchet, Peter, i. 212
Burdett, Sir Francis, ii. 139, 140
Burgoyne, Sir John, i. 25, 42
Burley, Sir Simon, execution of, i. 94
Burnet, Bishop, ii. 74, 77, 78, 79
Byron, Sir John, ii. 37, 38
Byward Tower, the, i. 10, 11, 21, 44
Cade’s Insurrection, i. 104, 105
Campion, hanged at Tyburn, i. 213
Cannon in the Tower, i. 73
Capel, Lord, escape and recapture of, ii. 46, 47; execution of, 47
Carew, Sir Alexander, execution of, ii. 44
Carew, Sir George, i. 218
Carew, Sir Nicholas, execution of, i. 152
Carew, Sir Peter, i. 194
Carr, Robert, see Earl of Somerset, ii. 17
Catherine of Arragon, i. 121, 123, 125
Catherine Howard, i. 35, 39; execution of, 160, 161
Catherine Parr, i. 162, 165, 170
Cato Street Conspiracy, the, ii. 140
Cecil, Sir Robert, i. 218, 219, 223; ii. 4
Chaplain’s House, the, i. 34
Charles I., journey to Spain, i. 19;
armour of, 72; treatment of Lord Loudon, ii. 33, 34; betrayal of Stafford, 34, 35; plot to seize the Tower, 36, 37
Charles II. and Colonel Blood, i. 42; ii. 70, 71; executions of regicides, 56; death of Sir Harry Vane, 59; visit to the Tower, 59; coronation, 59; courage during the Fire, 62; Papistical tendencies, 73; visit to the Tower on the day of Essex’s death, 76, 77
Chelmsford, Lord, ii. 146
Cholmondeley, Sir Richard and Lady, i. 40, 41, 127
Clarence, George, Duke of, i. 44, 108, 111, 112
Clarke, Mr G. J., quoted, i. 6, 44, 53, 57, 61
Clement, Gregory, execution of, ii. 56
Clifford, Gervase, Lord, imprisonment and suicide of, ii. 26
Cobham Tower, i. 30
Cobham, Thomas, i. 34
Cobham, Henry, Lord, i. 30; ii. 2, 3, 5; his career and death, 5, 6; his writings, 7
Cobham Family, history of the, ii. 5, 6, 7
Coke, Sir Edward, i. 27, 48; ii. 18, 27
Cold Harbour, i. 6, 23, 24
Combermere, Lord, i. 25
Commines, Philip de, quoted, i. 112, 117
Constable of the Tower, office of, i. 25
Constable Tower, the, i. 46
Constable, Sir Robert, execution of, i. 151
Conyers, Sir John, ii. 37, 38, 43
Cooke, Lawrence, execution of, i. 159, 160
Cooper, Sir Anthony Ashley, ii. 53
Corbet, Miles, execution of, ii. 61
Cornwallis, Sir Thomas, i. 198
Council Chamber, the, i. 26, 27, 57
Courtenay, Edward, Earl of Devonshire, i. 188
Courtenay, Henry, Marquis of Exeter, execution of, i. 152, 153
Coventry, Sir William, ii. 65, 66
Cowdray, paintings formerly at, i. 169, 170
Coxe, Dr, Bishop of Ely, i. 177
Cradle Tower, the, i. 50, 52,; restoration of, ii. 169, 172, 173; recent discoveries, 173
Cranmer, Archbishop, i. 21, 144, 147, 158, 187, 189
Cromarty, Earl of, ii. 116, 117, 118, 120, 133
Cromwell, Oliver, Constable of the Tower, ii. 38; plots to assassinate, 51, 52
Cromwell, Thomas, i. 19, 133, 143, 144, 148, 150, 151, 152; made Earl of Essex, 155; compared with Robespierre, 155; his career, 155–157; his fall, 157; execution of, 158
Cruikshank, G., ii. 143
Cuffe, Henry, execution of, i. 230
Cumberland, Earl of, i. 72
Dacre, Lord, execution of, i. 159
Daniell, John, i. 46, 47
Danvers, Sir Charles, execution of, i. 229
Darcey, Lord, execution of, i. 151, 153
Darcy, Sir John, i. 88
Darnley, Lord, i. 181, 206
Dartmouth, William Legge, Lord, i. 67
David, King of Scotland, i. 58
Davison, Elizabeth’s secretary, i. 216
de la Motte, Henry Francis, hanged at Tyburn, ii. 137
de Ros, Lord, quoted, i. 13, 37, 42, 56, 59, 149, 163; ii. 111, 112
Derwentwater, Earl of, ii. 102, 103; execution of, 104, 126
Desborough, Nathaniel, ii. 67
Desmond, Earl of, ii. 12
Develin Tower, the, i. 43, 52, 53
de Vere, Aubrey, Earl of Oxford, i. 109
Devereux Tower, the, i. 43
Dick, Rev. R., quoted, i. 33
Digby, Sir Everard, execution of, ii. 9
Dighton, one of the murderers of the two Princes, i. 116, 117
Dillon, Viscount, i. 65, 69, 71, 211 n.
Draper, Hugh, i. 48
Dudley, Edmund, execution of, i. 124
Dudley, Lord Guildford, i. 34, 182, 185, 189; execution of, 192; buried in the Tower, 194
Dudley, Lord Harry, i. 187
Dudley family, the, i. 31, 32
Dungeons, in the Wakefield Tower, i. 18; White Tower, 26; Flint Tower, 44; Salt Tower, 47; St John’s Chapel, 55
Edward I., i. 83; the Tower under, 85, 86
Edward II., the Tower under, i. 86, 87
Edward III., i. 36, 44; the Tower under, 88, 89
Edward IV., murder of sons of, i. 20, 21, 22, 55, 112, 114–118; defeats the Lancastrians, 107; coronation of, 108, 109; battle of Tewkesbury, 110; his additions to the Tower, 112; death, 112
Edward VI., coronation of, i. 169, 170; execution of Somerset, 176, 178; further executions, 179, 180
Edwards, Talbot, i. 42; ii. 68, 69, 70
Eliot, Sir John, imprisonment of, ii. 28, 29; death, 29, 30
Elizabeth, Queen, i. 10; figure of, on a wooden horse, 56; and the Countess of Lennox, 28, 206; birth, 132; relations with Lord Seymour, 170, 171; and Bishop Coxe, 177; visit to the Tower with Queen Mary, 188; imprisoned in the Tower, 198;
released, 200; visit to the Tower before her coronation, 202; her treatment of Catherine Grey, 203; her struggle with Mary Stuart, 206; the Ridolfi plot, 208; proceedings against the Jesuits, 212, 213; State prisoners, 214; the Babington plot, 215; imprisonment of Raleigh, 218; fall of Essex, 221; her last days, 230
Elizabeth, Queen of Henry VII., i. 60; coronation of, 121
Elizabeth Woodville, i. 109, 114
Empson, Sir Richard, execution of, i. 124
Essex, Arthur Capel, Earl of, ii. 74; death in the Tower, 75, 76, 77
Essex, Geoffrey de Mandeville, Earl of, i. 65, 80, 81
Essex, Robert Devereux, Earl of, i. 35, 43; armour of, 72; an enemy of Raleigh, 221; his person and position, 221; failure of his Irish expedition, 222, 223; imprisonment and trial of, 223; execution of, 224
Essex, Robert, Earl of, 229
Eu, Counts of, i. 88, 103
Evelyn, John, ii. 71, 83
Fabyan, quoted, i. 112–117
Fairfax, Sir Thomas, ii. 38
Fawkes, Guy, i. 26, 55; ii. 9
Feckenham, i. 191, 193
Felton, John, assassination of Buckingham, i. 29, 76; ii. 31; execution of, 32
Fenwick, Sir John, execution of, ii. 91
Ferrers, Lawrence Shirley, Earl, hanged at Tyburn, ii. 133–135
Fire of 1841, the, i. 27; ii. 142–144
Fisher, John, Bishop of Rochester, i. 29, 132, 133; imprisonment, 134; trial and execution, 135–138; buried in the Tower, 142
Fitz, Colonel, ii. 53
Fitzgerald, Gerald, Earl of Kildare, i. 142
Fitzgerald, Thomas, siege of Dublin Castle by, i. 142; hanged, 143
Flambard, Astronomer-Royal, i. 60
Flambard, Bishop, i. 54, 57, 79, 80
Flete, John de, i. 65
Flint Tower, the, i. 43
Forde, Thomas, i. 47
Forrest, one of the murderers of the two Princes, i. 116
Fraser, Sir Simon, i. 86
Freeman, Professor, i. 53, 54, 80
Gage, J., i. 47
Gage, Sir Thomas, i. 200
Galligman’s Tower, i. 53
Garden Tower, the, i. 20
Gardiner, Bishop of Winchester, i. 185, 188, 199
Gardiner, Mr S. R., quoted, i. 95, 97, 110, 113, ii. 114
Gardner, Sir James, ii. 42
Garnet, Father, i. 48; execution of, ii. 8, 9
Gates, Sir John, execution of, i. 187
“Gentleman-gaoler,” the, i. 12
Gerard, Father, i. 44, 48–51; ii. 8, 9
Gerard, Thomas, execution of, i. 159
Gerrard, John, execution of, ii. 51
Ghosts in the Tower, i. 26, 27
Gibbons, Grinling, i. 46
Gladstone and Sir Thomas More compared, i. 139
Gloucester, Gilbert de Clare, Earl of, i. 84
Gloucester, Humphrey, Duke of, i. 103
Gloucester, Richard, Duke of, i. 108, 110; made Protector, 112; his portrait, 113; imprisons his nephews, and declares them bastards, 114, 115; crowned 115. See Richard III.
Gloucester, Thomas of Woodstock, Duke of, revolt of, i. 94; arrest of, 95
Gloucester, Duchess of, i. 104
Glendower, Owen, i. 100
Gordon, Lord George, ii. 137
Gorges, Sir Arthur, i. 218
Gough, Sir Mathew, i. 105
Governor’s House, see King’s House
Green, one of the murderers of the two Princes, i. 116
Grey, Lady Catherine, i. 191; marriage with Lord Hertford, 203; imprisonment of, 204; death of, 205
Grey, Lady Jane, i. 33, 34, 35; marriage with Guildford Dudley, 182; enters the Tower in state, 182; imprisonment of, 185; trial of, 189; letters to her father, 190, 191; execution of, 192–4; buried in the Tower, 194
Grey, Lord John, i. 194
Grey, Lord Leonard, i. 143; execution of, 143, 159
Grey, Sir Richard, execution of, i. 114
Grey de Wilton, Lord, imprisonment and death of, ii. 2, 5, 7
Griffin, Edward, ii. 92, 93
Grillot, i. 45
Gundulf, Bishop of Rochester, i. 6, 54, 62
Gunpowder Plot, the, ii. 8
Gurney, Sir Richard, ii. 42
Hacker, Colonel, execution of, ii. 58
Haiward and Gascoigne’s plan of the Tower, i. 6, 7, 23, 43, 75
Hales, Sir Robert, murder of, i. 90, 91, 92
Hamilton, James, Duke of, ii. 45; execution of, 46
Hamilton, Sir Stephen, execution of, i. 151
Harley, Robert, Earl of Oxford, imprisonment of, ii. 100
Harrington, James, ii. 56, 57
Harrison, Major-General Thomas, execution of, ii. 56
Harvey, Sir George, ii. 9, 10
Hastings, Sir Edward, i, 198
Hastings, Lord, i. 35, 57; execution of, 114
Hengham, Ralph de, i. 86
Henry I., i. 6, 7, 81; imprisonment of Flambard by, 79
Henry III., i. 17, 36, 45, 51, 59, 76; buildings in the Tower due to, 82; obliged to take shelter in the Tower, 83
Henry IV., i. 98, 100
Henry V., i. 101, 102
Henry VI., his minority, i. 103; Cade’s insurrection, 104, 105; deposition and imprisonment of, 108, 110; murder of, 19, 110
Henry VII., i. 120–123
Henry VIII., i. 16, 37; armour of, 71; marriage with Catherine of Arragon, 125; his executions, 126; marriage with Anne Boleyn, 131; execution of More and Fisher, 132 _et seq._; execution of Anne Boleyn, 143 _et seq._; marriage with Jane Seymour, 150; marriage with Anne of Cleves, 157; execution of Cromwell, 158;
execution of Catherine Howard, 160; increasing cruelty, 166; imprisonment of Norfolk and Surrey, 166; death, 168
Henry, Duke of Normandy, i. 81
Henry, Prince of Wales, armour of, i. 72; friendship with Raleigh, ii. 12; death of, 16, 18
Hentzner, Paul, i. 8, 58, 66, 67, 69
Hertford, Lord, i. 203, 204, 205; marriage with Lady Catherine Grey, 203; imprisonment of, 204, 205
Hewet, Dr, execution of, ii. 52
Hocking, W. J., quoted, ii. 97, 99
Hogarth, his portrait of Lord Lovat, ii. 127
Holland, Earl of, execution of, ii. 46
Hopton, Sir Owen, i. 24, 213, 217
Hopton, Sir Ralph (afterwards Lord), ii. 41, 42
Hotham, Sir John, and Captain, execution of, ii. 44
Hudson, Mr W. H., quoted, i. 74
Hungerford, Lord, execution of, i. 158, 159
Hussey, Lord, execution of, i. 151, 153
Hutchinson, Mrs, i. 21, 41 n., 42, 112
Inner Ward, the, i. 12, 20, 45, 51
James I., portrait of, in the Council Chamber, i. 27; first visit to the Tower, ii. 1; his appearance, 4; treatment of the Cobhams, 6, 7;
treatment of Arabella Stuart, 13–15; betrayal of Raleigh, 23, 24
James II., Roman Catholicism, ii. 73, 84; visit to the Tower on the day of Essex’s death, 76, 77; appointments of Roman Catholics at Oxford, 85; trial of the Seven Bishops, 86, 87; flight, 88, 89
James, Prince, of Scotland, imprisonment of, i. 100, 101
James, Colonel John, execution of, ii. 56
“Jane of the Tower,” birth of, i. 87
Jean de Vienne, i. 88
Jerningham, Sir Henry, i. 196
Jerome, William, execution of, i. 159
Jewel House, the, i. 18, 45; ii. 68
Jews, imprisonment of, i. 55, 85
Jeffreys, Judge, i. 21; ii. 75, 79, 85, 86, 87, 89, 90
Joan of Kent, i. 60
John, King, the Tower besieged by, i. 82
John, King of France, i. 58, 88
Julius Cæsar’s Tower, i. 47; repairs in, 131
Kent, Hubert de Burgh, Earl of, i. 82
Kent, Thomas Holland, Earl of, i. 94, 96
Kenmure, Lord, ii. 102, 103; execution of, 104, 105
Keys, ceremony of receiving the, i. 22
King’s House, i. 14, 20, 23, 24–28
Kildare, Gerald Fitzgerald, Earl of, i. 39
Kildare, Thomas Fitzgerald, Earl of, i. 34
Kilmarnock, Lord, i. 40; ii. 116, 117; trial of, 118–120; execution of, 121–124
Knighton, Sir W., i. 144, 145, 147, 148
Knights Templars, imprisonment of the, i. 87
Knyvett, Sir A., i. 164
Lambert, John, escape of, ii. 54; recaptured and banished, 54, 55
Lancaster, Duke of, i. 97.
See Henry IV.
Lansdowne, George Granville, Earl of, ii. 95, 101
Lanthorn Tower, i. 6, 51, 52; ii. 173, 174; restoration of, 169
Latimer, Bishop, i. 15, 172, 187, 201
Laud, Archbishop, i. 21; imprisonment of, ii. 34; his room searched by Prynne, 39; trial and execution, 40
Lee, Sir Henry, i. 211
Legge’s Mount, i. 52
Leicester, Robert Dudley, Earl of, i. 31, 66, 72
Lennox, Countess of, i. 28, 206; imprisonment of, 206
Le Swifte, E., i. 27
Lieutenant of the Tower, office of, i. 25
Lilburne, Colonel John, ii. 48
Lion Gate and Tower, i. 7, 10
Lisle, Arthur Lisle, Viscount, death of, i. 161
Lithbury, Robert, i. 86
“Little Ease,” i. 162; ii. 9
“Little Hell,” i. 44
Llewellyn, death of, in escaping from the Tower, i. 83
Lollards, persecution of the, i. 101, 102
London, Visscher’s view of, in 1616, ii. 21, 22; the Fire, 62, 63; Hollar’s view of London before and after the Fire, 62
London, Lord Mayor imprisoned, ii. 136, 137
Longchamp, Bishop of Ely, i. 9, 82
Lopez, plot of, i. 220; execution of, 221
Loudon, Lord, ii. 33, 34
Lovat, Simon Fraser, Lord, i. 39, 40, 70; ii. 126, 127; trial, 128, 129; execution, 130–133
Love, Christopher, execution of, ii. 50
Lucas, Lord, ii. 88, 89, 91
Lucy, Richard de, i. 81
Luke, Sir Thomas, ii. 26
Lumley, William, execution of, i. 151
Lumsford, Sir Thomas, ii. 38
Lysons, Sir Daniel, i. 25
Macaulay, Lord, i. 35
MacMahon, Colonel, attempted escape from the Tower, ii. 45; execution, 45