100% found this document useful (16 votes)
130 views62 pages

(FREE PDF Sample) Professional C++ Gregoire Ebooks

Professional

Uploaded by

soirakevn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (16 votes)
130 views62 pages

(FREE PDF Sample) Professional C++ Gregoire Ebooks

Professional

Uploaded by

soirakevn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Download the full version of the textbook now at textbookfull.

com

Professional C++ Gregoire

https://textbookfull.com/product/professional-c-
gregoire/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Primary Mathematics Textbook 2B Jennifer Hoerst

https://textbookfull.com/product/primary-mathematics-
textbook-2b-jennifer-hoerst/

textbookfull.com

Professional C 4th Edition Marc Gregoire

https://textbookfull.com/product/professional-c-4th-edition-marc-
gregoire/

textbookfull.com

Professional C++ 5th Edition Marc Gregoire

https://textbookfull.com/product/professional-c-5th-edition-marc-
gregoire/

textbookfull.com

Seeing Autism through Parents Feedback Sketchnotes


Technology and Evidence based Practices Demetria Ennis-
Cole
https://textbookfull.com/product/seeing-autism-through-parents-
feedback-sketchnotes-technology-and-evidence-based-practices-demetria-
ennis-cole/
textbookfull.com
Indexes A Chapter from the Chicago Manual of Style 17 17th
Edition Coll.

https://textbookfull.com/product/indexes-a-chapter-from-the-chicago-
manual-of-style-17-17th-edition-coll/

textbookfull.com

Architectured Materials in Nature and Engineering


Archimats Yuri Estrin

https://textbookfull.com/product/architectured-materials-in-nature-
and-engineering-archimats-yuri-estrin/

textbookfull.com

Blood Moon An American Epic of War and Splendor in the


Cherokee Nation First Simon And Schuster Trade Paperback
Edition John Sedgwick
https://textbookfull.com/product/blood-moon-an-american-epic-of-war-
and-splendor-in-the-cherokee-nation-first-simon-and-schuster-trade-
paperback-edition-john-sedgwick/
textbookfull.com

BeagleBone Home Automation Blueprints 1st Edition Rodolfo


Giometti

https://textbookfull.com/product/beaglebone-home-automation-
blueprints-1st-edition-rodolfo-giometti/

textbookfull.com

Management Of Banking And Financial Services 4th Edition


Padmalatha Suresh & Justin Paul

https://textbookfull.com/product/management-of-banking-and-financial-
services-4th-edition-padmalatha-suresh-justin-paul/

textbookfull.com
Computer and Information Sciences 31st International
Symposium ISCIS 2016 Kraków Poland October 27 28 2016
Proceedings 1st Edition Tadeusz Czachórski
https://textbookfull.com/product/computer-and-information-
sciences-31st-international-symposium-iscis-2016-krakow-poland-
october-27-28-2016-proceedings-1st-edition-tadeusz-czachorski/
textbookfull.com
PROFESSIONAL
C++

INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xlvii

▸▸ PART I INTRODUCTION TO PROFESSIONAL C++


CHAPTER 1 A Crash Course in C++ and the Standard Library . . . . . . . . . . . . . . . . 3
CHAPTER 2 Working with Strings and String Views. . . . . . . . . . . . . . . . . . . . . . . . 57
CHAPTER 3 Coding with Style. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

▸▸ PART II PROFESSIONAL C++ SOFTWARE DESIGN


CHAPTER 4 Designing Professional C++ Programs. . . . . . . . . . . . . . . . . . . . . . . . 95
CHAPTER 5 Designing with Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
CHAPTER 6 Designing for Reuse. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

▸▸ PART III C++ CODING THE PROFESSIONAL WAY


CHAPTER 7 Memory Management. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
CHAPTER 8 Gaining Proficiency with Classes and Objects. . . . . . . . . . . . . . . . . 199
CHAPTER 9 Mastering Classes and Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
CHAPTER 10 Discovering Inheritance Techniques. . . . . . . . . . . . . . . . . . . . . . . . . 277
CHAPTER 11 C++ Quirks, Oddities, and Incidentals . . . . . . . . . . . . . . . . . . . . . . . 333
CHAPTER 12 Writing Generic Code with Templates . . . . . . . . . . . . . . . . . . . . . . . 373
CHAPTER 13 Demystifying C++ I/O. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
CHAPTER 14 Handling Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
CHAPTER 15 Overloading C++ Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
CHAPTER 16 Overview of the C++ Standard Library. . . . . . . . . . . . . . . . . . . . . . . 507
CHAPTER 17 Understanding Containers and Iterators . . . . . . . . . . . . . . . . . . . . . 535
CHAPTER 18 Mastering Standard Library Algorithms. . . . . . . . . . . . . . . . . . . . . . 607
CHAPTER 19 String Localization and Regular Expressions . . . . . . . . . . . . . . . . . . 663
CHAPTER 20 Additional Library Utilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691

Continues
▸▸ PART IV MASTERING ADVANCED FEATURES OF C++
CHAPTER 21 Customizing and Extending the Standard Library. . . . . . . . . . . . . . 727
CHAPTER 22 Advanced Templates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775
CHAPTER 23 Multithreaded Programming with C++. . . . . . . . . . . . . . . . . . . . . . . 813

▸▸ PART V C++ SOFTWARE ENGINEERING


CHAPTER 24 Maximizing Software Engineering Methods. . . . . . . . . . . . . . . . . . 859
CHAPTER 25 Writing Efficient C++. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 881
CHAPTER 26 Becoming Adept at Testing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 909
CHAPTER 27 Conquering Debugging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933
CHAPTER 28 Incorporating Design Techniques and Frameworks. . . . . . . . . . . . . 971
CHAPTER 29 Applying Design Patterns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991
CHAPTER 30  eveloping Cross-Platform and
D
Cross-Language Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1017
APPENDIX A C++ Interviews. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1039
APPENDIX B Annotated Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1063
APPENDIX C Standard Library Header Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1075
APPENDIX D Introduction to UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1083

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1087
PROFESSIONAL

C++
PROFESSIONAL

C++
Fourth Edition

Marc Gregoire
Professional C++, Fourth Edition
Published by
John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2018 by John Wiley & Sons, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-1-119-42130-6
ISBN: 978-1-119-42126-9 (ebk)
ISBN: 978-1-119-42122-1 (ebk)

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers,
MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the
Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-
6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with
respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including
without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or pro-
motional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold
with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services.
If professional assistance is required, the services of a competent professional person should be sought. Neither the pub-
lisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to
in this work as a citation and/or a potential source of further information does not mean that the author or the publisher
endorses the information the organization or Web site may provide or recommendations it may make. Further, readers
should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was
written and when it is read.

For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with stan-
dard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such
as a CD or DVD that is not included in the version you purchased, you may download this material at http://
booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 2017963243
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trade-
marks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries,
and may not be used without written permission. All other trademarks are the property of their respective owners. John
Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book.
Dedicated to my parents and my brother, who are
always there for me. Their support and patience
helped me in finishing this book.
ABOUT THE AUTHOR

MARC GREGOIRE is a software architect from Belgium. He graduated from the University of Leuven,
Belgium, with a degree in “Burgerlijk ingenieur in de computer wetenschappen” (equivalent to mas-
ter of science in engineering: computer science). The year after, he received an advanced master’s
degree in artificial intelligence, cum laude, at the same university. After his studies, Marc started
working for a software consultancy company called Ordina Belgium. As a consultant, he worked for
Siemens and Nokia Siemens Networks on critical 2G and 3G software running on Solaris for tele-
com operators. This required working with international teams stretching from South America and
the United States to Europe, the Middle East, Africa, and Asia. Now, Marc is a software architect at
Nikon Metrology (www.nikonmetrology.com), a division of Nikon and a leading provider of preci-
sion optical instruments and metrology solutions for 3D geometric inspection.
His main expertise is in C/C++, and specifically Microsoft VC++ and the MFC framework. He has
experience in developing C++ programs running 24/7 on Windows and Linux platforms: for exam-
ple, KNX/EIB home automation software. In addition to C/C++, Marc also likes C# and uses PHP
for creating web pages.
Since April 2007, he has received the annual Microsoft MVP (Most Valuable Professional) award
for his Visual C++ expertise.
Marc is the founder of the Belgian C++ Users Group (www.becpp.org), co-author of C++ Standard
Library Quick Reference (Apress), technical editor for numerous books for several publishers, and
a member on the CodeGuru forum (as Marc G). He maintains a blog at www.nuonsoft.com/blog/,
and is passionate about traveling and gastronomic restaurants.
ABOUT THE TECHNICAL EDITOR

PETER VAN WEERT is a Belgian software engineer, whose main interests and expertise are in C++,
programming languages, algorithms, and data structures.
He received his master of science in computer science from the University of Leuven, Belgium,
summa cum laude, with congratulations of the Board of Examiners. In 2010, the same university
awarded him a PhD for his research on the efficient compilation of rule-based programming lan-
guages (mainly Java). During his doctoral studies, he was a teaching assistant for courses on object-
oriented analysis and design, Java programming, and declarative programming languages.
After his studies, Peter worked for Nikon Metrology on large-scale, industrial-application software
in the area of 3D laser scanning and point cloud inspection. In 2017, he joined the software R&D
unit of Nobel Biocare, which specializes in digital dentistry software. Throughout his professional
career, Peter has mastered C++ software development, as well as the management, refactoring, and
debugging of very large code bases. He also gained further proficiency in all aspects of the software
development process, including the analysis of functional and technical requirements, and Agile-
and Scrum-based project and team management.
Peter is a regular speaker at, and board member of, the Belgian C++ Users Group. He also co-
authored two books: C++ Standard Library Quick Reference and Beginning C++ (5th edition), both
published by Apress.
CREDITS

PROJECT EDITOR EXECUTIVE EDITOR


Adaobi Obi Tulton Jim Minatel

TECHNICAL EDITOR PROJECT COORDINATOR, COVER


Peter Van Weert Brent Savage

PRODUCTION EDITOR PROOFREADER


Athiyappan Lalith Kumar Nancy Bell

COPY EDITOR INDEXER


Marylouise Wiack Johnna VanHoose Dinse

MANAGER OF CONTENT DEVELOPMENT COVER DESIGNER


AND ASSEMBLY Wiley
Mary Beth Wakefield
COVER IMAGE
PRODUCTION MANAGER © ittipon/Shutterstock
Kathleen Wisor

MARKETING MANAGER
Christie Hilbrich
ACKNOWLEDGMENTS

I THANK THE JOHN WILEY & SONS AND WROX Press editorial and production teams for their sup-
port. Especially, thank you to Jim Minatel, executive editor at Wiley, for giving me a chance to
write this new edition, Adaobi Obi Tulton, project editor, for managing this project, and Marylouise
Wiack, copy editor, for improving readability and consistency and making sure the text is gram-
matically correct.
A very special thank you to my technical editor, Peter Van Weert, for his outstanding technical
review. His many constructive comments and ideas have certainly made this book better.
Of course, the support and patience of my parents and my brother were very important in finishing
this book. I would also like to express my sincere gratitude toward my employer, Nikon Metrology,
for supporting me during this project.
Finally, I thank you, the reader, for trying this approach to professional C++ software development.
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
CONTENTS

INTRODUCTION xlvii

Part I: INTRODUCTION TO PROFESSIONAL C++

Chapter 1: A CRASH COURSE IN C++


AND THE STANDARD LIBRARY 3

The Basics of C++ 4


The Obligatory Hello, World 4
Comments 4
Preprocessor Directives 5
The main() Function 6
I/O Streams 7
Namespaces 8
Literals 10
Variables 10
Operators 13
Types 15
Enumerated Types 15
Structs 16
Conditional Statements 17
if/else Statements 17
switch Statements 18
The Conditional Operator 20
Logical Evaluation Operators 20
Functions 21
Function Return Type Deduction 22
Current Function’s Name 23
C-Style Arrays 23
std::array 25
std::vector 25
Structured Bindings 26
Loops 26
The while Loop 26
The do/while Loop 27
The for Loop 27
CONTENTS

The Range-Based for Loop 27


Initializer Lists 28
Those Are the Basics 28
Diving Deeper into C++ 28
Strings in C++ 29
Pointers and Dynamic Memory 29
The Stack and the Heap 29
Working with Pointers 30
Dynamically Allocated Arrays 31
Null Pointer Constant 32
Smart Pointers 33
The Many Uses of const 35
const Constants 35
const to Protect Parameters 35
References 35
Pass By Reference 36
Pass By const Reference 37
Exceptions 37
Type Inference 38
The auto Keyword 39
The decltype Keyword 40
C++ as an Object-Oriented Language 40
Defining Classes 40
Using Classes 43
Uniform Initialization 43
Direct List Initialization versus Copy List Initialization 45
The Standard Library 46
Your First Useful C++ Program 46
An Employee Records System 46
The Employee Class 47
Employee.h 47
Employee.cpp 48
EmployeeTest.cpp 50
The Database Class 50
Database.h 50
Database.cpp 51
DatabaseTest.cpp 52
The User Interface 53
Evaluating the Program 55
Summary 56

xviii
CONTENTS

Chapter 2: WORKING WITH STRINGS AND STRING VIEWS 57

Dynamic Strings 58
C-Style Strings 58
String Literals 60
Raw String Literals 60
The C++ std::string Class 62
What Is Wrong with C-Style Strings? 62
Using the string Class 62
std::string Literals 64
High-Level Numeric Conversions 64
Low-Level Numeric Conversions 65
The std::string_view Class 67
std::string_view Literals 69
Nonstandard Strings 69
Summary 69

Chapter 3: CODING WITH STYLE 71

The Importance of Looking Good 71


Thinking Ahead 72
Elements of Good Style 72
Documenting Your Code 72
Reasons to Write Comments 72
Commenting to Explain Usage 72
Commenting to Explain Complicated Code 74
Commenting to Convey Meta-information 75
Commenting Styles 77
Commenting Every Line 77
Prefix Comments 78
Fixed-Format Comments 79
Ad Hoc Comments 80
Self-Documenting Code 81
Decomposition 81
Decomposition through Refactoring 82
Decomposition by Design 83
Decomposition in This Book 83
Naming 83
Choosing a Good Name 83
Naming Conventions 84
Counters 84
Prefixes 84

xix
CONTENTS

Hungarian Notation 85
Getters and Setters 86
Capitalization 86
Namespaced Constants 86
Using Language Features with Style 86
Use Constants 87
Use References Instead of Pointers 87
Use Custom Exceptions 88
Formatting 88
The Curly Brace Alignment Debate 88
Coming to Blows over Spaces and Parentheses 89
Spaces and Tabs 90
Stylistic Challenges 90
Summary 91

Part II: PROFESSIONAL C++ SOFTWARE DESIGN

Chapter 4: DESIGNING PROFESSIONAL C++ PROGRAMS 95

What Is Programming Design? 96


The Importance of Programming Design 97
Designing for C++ 99
Two Rules for C++ Design 100
Abstraction 100
Benefiting from Abstraction 100
Incorporating Abstraction in Your Design 101
Reuse 101
Writing Reusable Code 102
Reusing Designs 103
Reusing Existing Code 103
A Note on Terminology 104
Deciding Whether or Not to Reuse Code 105
Advantages to Reusing Code 105
Disadvantages to Reusing Code 105
Putting It Together to Make a Decision 106
Strategies for Reusing Code 107
Understand the Capabilities and Limitations 107
Understand the Performance 108
Understand Platform Limitations 110
Understand Licensing and Support 110
Know Where to Find Help 111
Prototype 111

xx
CONTENTS

Bundling Third-Party Applications 112


Open-Source Libraries 112
The Open-Source Movements 112
Finding and Using Open-Source Libraries 113
Guidelines for Using Open-Source Code 113
The C++ Standard Library 114
C Standard Library 114
Deciding Whether or Not to Use the Standard Library 114
Designing a Chess Program 114
Requirements 115
Design Steps 115
Divide the Program into Subsystems 115
Choose Threading Models 117
Specify Class Hierarchies for Each Subsystem 118
Specify Classes, Data Structures, Algorithms, and Patterns for Each
Subsystem 118
Specify Error Handling for Each Subsystem 120
Summary 121

Chapter 5: DESIGNING WITH OBJECTS 123

Am I Thinking Procedurally? 124


The Object-Oriented Philosophy 124
Classes 124
Components 125
Properties 125
Behaviors 126
Bringing It All Together 126
Living in a World of Objects 127
Over-Objectification 127
Overly General Objects 128
Object Relationships 129
The Has-A Relationship 129
The Is-A Relationship (Inheritance) 130
Inheritance Techniques 130
Polymorphism versus Code Reuse 131
The Fine Line between Has-A and Is-A 132
The Not-A Relationship 135
Hierarchies 136
Multiple Inheritance 137
Mixin Classes 138

xxi
CONTENTS

Abstraction 138
Interface versus Implementation 138
Deciding on an Exposed Interface 139
Consider the Audience 139
Consider the Purpose 139
Consider the Future 141
Designing a Successful Abstraction 141
Summary 142

Chapter 6: DESIGNING FOR REUSE 143

The Reuse Philosophy 144


How to Design Reusable Code 144
Use Abstraction 145
Structure Your Code for Optimal Reuse 146
Avoid Combining Unrelated or Logically Separate Concepts 146
Use Templates for Generic Data Structures and Algorithms 148
Provide Appropriate Checks and Safeguards 150
Design for Extensibility 151
Design Usable Interfaces 153
Design Interfaces That Are Easy to Use 153
Design General-Purpose Interfaces 157
Reconciling Generality and Ease of Use 157
The SOLID Principles 158
Summary 159

Part III: C++ CODING THE PROFESSIONAL WAY

Chapter 7: MEMORY MANAGEMENT 163

Working with Dynamic Memory 164


How to Picture Memory 164
Allocation and Deallocation 166
Using new and delete 166
What about My Good Friend malloc? 167
When Memory Allocation Fails 167
Arrays 168
Arrays of Basic Types 168
Arrays of Objects 170
Deleting Arrays 171
Multi-dimensional Arrays 172
Working with Pointers 175

xxii
CONTENTS

A Mental Model for Pointers 175


Casting with Pointers 176
Array-Pointer Duality 177
Arrays Are Pointers! 177
Not All Pointers Are Arrays! 179
Low-Level Memory Operations 179
Pointer Arithmetic 179
Custom Memory Management 180
Garbage Collection 181
Object Pools 182
Smart Pointers 182
unique_ptr 183
Creating unique_ptrs 183
Using unique_ptrs 185
unique_ptr and C-Style Arrays 186
Custom Deleters 186
shared_ptr 186
Casting a shared_ptr 187
The Need for Reference Counting 188
Aliasing 189
weak_ptr 189
Move Semantics 190
enable_shared_from_this 191
The Old Deprecated/Removed auto_ptr 192
Common Memory Pitfalls 192
Underallocating Strings 192
Accessing Out-of-Bounds Memory 193
Memory Leaks 194
Finding and Fixing Memory Leaks in Windows with Visual C++ 195
Finding and Fixing Memory Leaks in Linux with Valgrind 196
Double-Deleting and Invalid Pointers 197
Summary 197

Chapter 8: GAINING PROFICIENCY WITH CLASSES AND OBJECTS 199

Introducing the Spreadsheet Example 200


Writing Classes 200
Class Definitions 200
Class Members 201
Access Control 201
Order of Declarations 203
In-Class Member Initializers 203

xxiii
CONTENTS

Defining Methods 203


Accessing Data Members 204
Calling Other Methods 204
The this Pointer 206
Using Objects 207
Objects on the Stack 207
Objects on the Heap 207
Object Life Cycles 208
Object Creation 208
Writing Constructors 209
Using Constructors 210
Providing Multiple Constructors 211
Default Constructors 212
Constructor Initializers 215
Copy Constructors 218
Initializer-List Constructors 220
Delegating Constructors 222
Summary of Compiler-Generated Constructors 222
Object Destruction 224
Assigning to Objects 225
Declaring an Assignment Operator 225
Defining an Assignment Operator 226
Explicitly Defaulted and Deleted Assignment Operator 227
Compiler-Generated Copy Constructor and Copy Assignment Operator 228
Distinguishing Copying from Assignment 228
Objects as Return Values 228
Copy Constructors and Object Members 229
Summary 230

Chapter 9: MASTERING CLASSES AND OBJECTS 231

Friends 232
Dynamic Memory Allocation in Objects 233
The Spreadsheet Class 233
Freeing Memory with Destructors 235
Handling Copying and Assignment 236
The Spreadsheet Copy Constructor 239
The Spreadsheet Assignment Operator 240
Disallowing Assignment and Pass-By-Value 242
Handling Moving with Move Semantics 243
Rvalue References 243
Implementing Move Semantics 245

xxiv
CONTENTS

Testing the Spreadsheet Move Operations 248


Implementing a Swap Function with Move Semantics 250
Rule of Zero 250
More about Methods 251
static Methods 251
const Methods 251
mutable Data Members 253
Method Overloading 253
Overloading Based on const 254
Explicitly Deleting Overloads 255
Inline Methods 255
Default Arguments 257
Different Kinds of Data Members 258
static Data Members 258
Inline Variables 259
Accessing static Data Members within Class Methods 259
Accessing static Data Members Outside Methods 260
const static Data Members 260
Reference Data Members 261
const Reference Data Members 262
Nested Classes 263
Enumerated Types inside Classes 264
Operator Overloading 265
Example: Implementing Addition for SpreadsheetCells 265
First Attempt: The add Method 265
Second Attempt: Overloaded operator+ as a Method 266
Third Attempt: Global operator+ 268
Overloading Arithmetic Operators 269
Overloading the Arithmetic Shorthand Operators 269
Overloading Comparison Operators 270
Building Types with Operator Overloading 271
Building Stable Interfaces 272
Using Interface and Implementation Classes 272
Summary 275
Chapter 10: DISCOVERING INHERITANCE TECHNIQUES 277

Building Classes with Inheritance 278


Extending Classes 278
A Client’s View of Inheritance 279
A Derived Class’s View of Inheritance 280
Preventing Inheritance 281

xxv
CONTENTS

Overriding Methods 281


How I Learned to Stop Worrying and Make Everything virtual 281
Syntax for Overriding a Method 282
A Client’s View of Overridden Methods 283
The override Keyword 284
The Truth about virtual 286
Preventing Overriding 290
Inheritance for Reuse 291
The WeatherPrediction Class 291
Adding Functionality in a Derived Class 292
Replacing Functionality in a Derived Class 293
Respect Your Parents 294
Parent Constructors 294
Parent Destructors 296
Referring to Parent Names 297
Casting Up and Down 299
Inheritance for Polymorphism 301
Return of the Spreadsheet 301
Designing the Polymorphic Spreadsheet Cell 301
The SpreadsheetCell Base Class 302
A First Attempt 302
Pure Virtual Methods and Abstract Base Classes 303
The Individual Derived Classes 304
StringSpreadsheetCell Class Definition 304
StringSpreadsheetCell Implementation 304
DoubleSpreadsheetCell Class Definition and Implementation 305
Leveraging Polymorphism 306
Future Considerations 306
Multiple Inheritance 308
Inheriting from Multiple Classes 308
Naming Collisions and Ambiguous Base Classes 309
Name Ambiguity 309
Ambiguous Base Classes 311
Uses for Multiple Inheritance 312
Interesting and Obscure Inheritance Issues 312
Changing the Overridden Method’s Characteristics 313
Changing the Method Return Type 313
Changing the Method Parameters 315
Inherited Constructors 316
Special Cases in Overriding Methods 320

xxvi
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
CONTENTS

The Base Class Method Is static 320


The Base Class Method Is Overloaded 321
The Base Class Method Is private or protected 322
The Base Class Method Has Default Arguments 324
The Base Class Method Has a Different Access Level 325
Copy Constructors and Assignment Operators in Derived Classes 327
Run-Time Type Facilities 329
Non-public Inheritance 331
Virtual Base Classes 331
Summary 332

Chapter 11: C++ QUIRKS, ODDITIES, AND INCIDENTALS 333

References 334
Reference Variables 334
Modifying References 335
References to Pointers and Pointers to References 336
Reference Data Members 336
Reference Parameters 336
References from Pointers 337
Pass-by-Reference versus Pass-by-Value 337
Reference Return Values 338
Rvalue References 338
Deciding between References and Pointers 339
Keyword Confusion 343
The const Keyword 343
const Variables and Parameters 343
const Methods 345
The constexpr Keyword 346
The static Keyword 347
static Data Members and Methods 347
static Linkage 347
static Variables in Functions 350
Order of Initialization of Nonlocal Variables 351
Order of Destruction of Nonlocal Variables 351
Types and Casts 351
Type Aliases 352
Type Aliases for Function Pointers 353
Type Aliases for Pointers to Methods and Data Members 355
typedefs 356

xxvii
CONTENTS

Casts 357
const_cast() 357
static_cast() 358
reinterpret_cast() 359
dynamic_cast() 360
Summary of Casts 361
Scope Resolution 362
Attributes 363
[[noreturn]] 363
[[deprecated]] 364
[[fallthrough]] 364
[[nodiscard]] 364
[[maybe_unused]] 365
Vendor-Specific Attributes 365
User-Defined Literals 365
Standard User-Defined Literals 367
Header Files 367
C Utilities 369
Variable-Length Argument Lists 369
Accessing the Arguments 370
Why You Shouldn’t Use C-Style Variable-Length Argument Lists 371
Preprocessor Macros 371
Summary 372

Chapter 12: WRITING GENERIC CODE WITH TEMPLATES 373

Overview of Templates 374


Class Templates 375
Writing a Class Template 375
Coding without Templates 375
A Template Grid Class 378
Using the Grid Template 382
Angle Brackets 383
How the Compiler Processes Templates 383
Selective Instantiation 384
Template Requirements on Types 384
Distributing Template Code between Files 384
Template Definitions in Header Files 384
Template Definitions in Source Files 385
Template Parameters 386
Non-type Template Parameters 387

xxviii
CONTENTS

Default Values for Type Parameters 389


Template Parameter Deduction for Constructors 389
Method Templates 391
Method Templates with Non-type Parameters 393
Class Template Specialization 395
Deriving from Class Templates 397
Inheritance versus Specialization 399
Alias Templates 399
Function Templates 400
Function Template Specialization 401
Function Template Overloading 402
Function Template Overloading and Specialization Together 403
Friend Function Templates of Class Templates 403
More on Template Parameter Deduction 404
Return Type of Function Templates 405
Variable Templates 407
Summary 407
Chapter 13: DEMYSTIFYING C++ I/O 409

Using Streams 410


What Is a Stream, Anyway? 410
Stream Sources and Destinations 411
Output with Streams 411
Output Basics 412
Methods of Output Streams 412
Handling Output Errors 414
Output Manipulators 415
Input with Streams 417
Input Basics 417
Handling Input Errors 418
Input Methods 419
Input Manipulators 423
Input and Output with Objects 423
String Streams 425
File Streams 426
Text Mode versus Binary Mode 427
Jumping around with seek() and tell() 428
Linking Streams Together 430
Bidirectional I/O 431
Summary 432

xxix
CONTENTS

Chapter 14: HANDLING ERRORS 433

Errors and Exceptions 434


What Are Exceptions, Anyway? 434
Why Exceptions in C++ Are a Good Thing 434
Recommendation 436
Exception Mechanics 436
Throwing and Catching Exceptions 437
Exception Types 439
Catching Exception Objects by const Reference 440
Throwing and Catching Multiple Exceptions 441
Matching and const 443
Matching Any Exception 443
Uncaught Exceptions 444
noexcept 445
Throw Lists (Deprecated/Removed) 446
Exceptions and Polymorphism 446
The Standard Exception Hierarchy 446
Catching Exceptions in a Class Hierarchy 448
Writing Your Own Exception Classes 449
Nested Exceptions 452
Rethrowing Exceptions 454
Stack Unwinding and Cleanup 456
Use Smart Pointers 457
Catch, Cleanup, and Rethrow 458
Common Error-Handling Issues 459
Memory Allocation Errors 459
Non-throwing new 460
Customizing Memory Allocation Failure Behavior 460
Errors in Constructors 462
Function-Try-Blocks for Constructors 464
Errors in Destructors 467
Putting It All Together 468
Summary 472
Chapter 15: OVERLOADING C++ OPERATORS 473

Overview of Operator Overloading 474


Why Overload Operators? 474
Limitations to Operator Overloading 474
Choices in Operator Overloading 475
Method or Global Function 475

xxx
CONTENTS

Choosing Argument Types 476


Choosing Return Types 477
Choosing Behavior 477
Operators You Shouldn’t Overload 477
Summary of Overloadable Operators 478
Rvalue References 481
Relational Operators 482
Overloading the Arithmetic Operators 483
Overloading Unary Minus and Unary Plus 483
Overloading Increment and Decrement 483
Overloading the Bitwise and Binary Logical Operators 484
Overloading the Insertion and Extraction Operators 485
Overloading the Subscripting Operator 486
Providing Read-Only Access with operator[] 489
Non-integral Array Indices 490
Overloading the Function Call Operator 491
Overloading the Dereferencing Operators 492
Implementing operator* 494
Implementing operator–> 494
What in the World Are operator.* and operator–>*? 495
Writing Conversion Operators 496
Solving Ambiguity Problems with Explicit Conversion Operators 497
Conversions for Boolean Expressions 498
Overloading the Memory Allocation and Deallocation Operators 500
How new and delete Really Work 500
The New-Expression and operator new 501
The Delete-Expression and operator delete 501
Overloading operator new and operator delete 501
Explicitly Deleting/Defaulting operator new and operator delete 504
Overloading operator new and operator delete with Extra Parameters 504
Overloading operator delete with Size of Memory as Parameter 505
Summary 506

Chapter 16: OVERVIEW OF THE C++ STANDARD LIBRARY 507

Coding Principles 508


Use of Templates 508
Use of Operator Overloading 509
Overview of the C++ Standard Library 509
Strings 509
Regular Expressions 510
I/O Streams 510

xxxi
Random documents with unrelated
content Scribd suggests to you:
given to their play by one taking the head of the other between his
fore-flippers, as if about to salute him, or more likely her, in the
orthodox fashion. One was seen the other morning in possession of
a large fish, while a number of gulls sat at a safe distance round
him, waiting for the fragments when the feast should begin. By the
way he glared at them, he was evidently annoyed at their presence.
Sinking for a few seconds, he appeared on the surface minus the
fish. This was evidently intended as a ruse, and meant to imply that
he had lost it; but the gulls seemed to know better, and kept their
position. Diving, he made his appearance some distance off, this
time with the fish in his mouth, only to find himself, to his
annoyance, again the centre of wistful expectations. Presuming
these gulls to be up-to-date birds, their exulting cacklings might be
literally rendered—“You better begin, Mister Phoca; it’s no use trying,
you know; you can’t possibly dewett us!” At least, the seal seemed
to think so, for he there and then opened the banquet with a rip of
his teeth that distributed the offal amongst the hungry cordon.
The rocks become at this season of the year invested with a
slippery coating of algæ, which renders it extremely difficult to
maintain one’s footing, and also necessitates repeated applications
of hot lime to our gratings in order to render them passable. Myriads
of minute whelks, no larger than turnip seed, strew the rocks and
crunch under foot as we walk, while great patches of mussel spawn
delight the heart of the more venturesome of the white whelks—a
prospecting party who will doubtless communicate the promising
state of the commissariat to their fellows still in winter quarters.
Fishing in the Rock pools has been tried for the first time this
season, and resulted in the capture of a solitary “cobbler.” It may be
a month hence before we meet with any success.
This month has been extremely mild, though the hills behind
Arbroath are still seen to carry portions of their winter coat, while
the higher ranges inland are completely snow-capped. On a clear
day our view is limited by Tod Head, about twenty-five miles to the
north, and St Abb’s Head thirty miles south of us. The coast-line
presents a uniform flatness, which becomes monotonous in
comparison with the more picturesque raggedness of the West
Coast. A most conspicuous feature in the landscape in the vicinity of
Arbroath is the clump of trees on the summit of the Law Hill—a
landmark well known to navigators, and easily discernible, as it
stands sharply defined against the sky-line. Arbroath, when not
enveloped in smoke, is clearly seen, and with the aid of our
telescope the after-church promenaders can be distinguished on the
Protection Wall, or wending their way towards the Victoria Park.
APRIL 1902.

The extremely low tides prevalent at the opening of the month


enabled us to extend our hunting grounds somewhat further than
usual, and also to reach and demolish several “travellers” which the
heavy seas had hurled into the boat tracks, thus constituting a
serious danger at relief times. Quite a forest of luxuriant tangles now
cover the lower lying portion of the reef. Their dripping blades
appear on the surface, scintillating in the brilliant sunshine like so
many diamonds, till the receding tide permits the warm sun to rob
them of their freshness, their beauty vanishing in a perceptible
vapour, leaving them flaccid and inert till the returning tide restores
their pristine beauty. The badderlock or henware is here also in great
profusion, and usually selects a position the reverse of peaceful,
being generally found where the wash of the seas is most constant.
Of rapid growth, they attain a great length, some measuring fully
sixteen feet; one we had under observation was seen to increase a
foot in length in six weeks time. Owing to hazy weather we had a
number of compulsory visitors to dinner yesterday. Seated outside
our kitchen window was a party of fog-bound travellers, consisting of
a pigeon, a starling, a wagtail, a robin, and a couple of wheatears.
The starling was sitting bunched up by himself, preserving a stolid
indifference at his enforced detention, and appeared to treat the
animated expansion and flirting of the wheatears’ tails as undue
levity, unbecoming their sorrowful predicament. The beautiful black-
throated wagtail is all alertness, and the slightest movement on our
part sends him circling round the Rock till, unable to sight the land,
he is fain to regain his resting place. The pigeon has been here a
week now, and evidently has no intention of leaving. Should the
window be left open he makes bold enough to enter, although but
the other day he gave us a somewhat dramatic illustration of the
proverbial hen on the hot “griddle” by rehearsing a fandango on the
top of our cooking range, a position from which he had to be forcibly
removed. To-day, the 21st, he has been joined by a companion of
his own species, a red-chequered homer; but instead of the mutual
demonstrations of pleasure one would expect to witness at their
meeting in such isolation, they remained quite indifferent to each
other’s presence, the newcomer possibly from motives of disdain, as
he appears to belong to the aristocracy, seeing he sports an
aluminium bracelet, on which are the letters “U.B.” and the year
1901, besides a number composed of three figures, which,
unfortunately, I took no note of. A strong southerly breeze on the
22nd deprived us of their company. Losing the shelter of the tower,
they were unable to make headway against the wind, and,
fortunately for themselves, were driven landwards.
On the 20th a small patch of paidle-fish spawn was seen
cemented in a sheltered nook of the rocks. This is unusually early for
nesting operations, as it is generally May before they are much in
evidence here. The extremely small quantity may denote a change
of mind on the part of the depositor; besides, the site is badly
chosen, as the nest is a couple of feet above low water, and
consequently without the cock’s guardianship for some time each
tide. Possibly the heavy seas prevalent during the past fortnight may
have warned the builder of being somewhat premature in her
operations.
We had ocular demonstration the other day concerning a matter
of which doubts have been expressed, namely, the skinning of their
prey by seals. Not only do they skin their fish, but each shred of skin
is greedily swallowed as soon as stripped. The skinning entails a
good deal of trouble, as the fish is pushed away from the seal at
every mouthful, and consequently sinks, so that a dive is necessary
each time in order to resume operations. Why he should take all this
trouble is not apparent, but presumably he understands his own
business best. His operations at present are watched by us with
longing eyes, for though he appears to have all he wants we are as
yet fishless. However, the presence of the paidle spawn is a hopeful
sign, and is the first attraction for the wandering cod, by whom it is
greedily devoured, providing they can steal a march on the red-
coated sentry—a difficult matter, one would think, considering how
assiduous he is in the protection of his charge. The white whelks,
presumably adopting the promising report of the reconnoitring party
sent out last month, have turned out en masse, and are now waging
a one-sided war of extermination upon the defenceless mussels.
The times change and we change with them. Our present light is
doomed, and what the assaults of almost a century’s gales have
failed to accomplish will succumb to the demands of modern
innovation. Doubtless, the presiding genius of the reef will be
congratulating himself, as he bares his head each tide to witness the
process of demolition, on the return of the palmy days when as yet
no meddling light interfered with the working of his own sweet will
in dealing death and destruction to many a stout ship. Happily, this
view is only apparent, for by early autumn a much more powerful
light will be installed, and a new lease of life granted to the grand
old building which has so effectively served the maritime world since
1811. Probably but few on shore noticed the first appearance of the
temporary light on the evening of the 30th. Of weaker power, but
presenting similar characteristics as the future light, namely, red and
white flashes alternately, with an interval of thirty seconds between
each flash, it will remain in use till ousted by its more powerful
successor.
MAY 1902.

December in May fitly describes the prevailing state of the weather


during this month. Chilling winds, accompanied by snow, hail, or
sleet showers, engender doubts as to the veracity of the calendar,
but the arrival of a number of terns on the 18th dispels all doubts
upon the matter. Sojourning in Africa since their departure in
September, they invariably make their appearance here in May. At
present there are about thirty of these energetic little birds busy
diving among the breakers, picking up small fry, among which is
seen inch long sand eels. A flock of kittiwake gulls also hunt
alongside of them, while several gannets are to be seen further off,
plunging in pursuit of larger game. Clustered in sheltering nooks of
the rock are numerous patches of ova, deposited by the white
whelk. Closely resembling ears of wheat in size and shape, each is
attached to the rock by a short footstalk, terminating in a flattened
disc. On being pressed, a milky fluid, somewhat granular, is exuded
from the free end. The whelks themselves are at present feasting on
limpets, whose shells have been fractured by the debris consequent
on the alterations in progress, though at other times they do not
appear to attack the limpets, their thick shells possibly making the
game not worth the candle.
Despite the inclemency of the weather, the work in connection
with the alterations is being rapidly pushed forward. The removal of
the old lantern and parapet wall turned out a more laborious
undertaking than the erection of the new ones. Strength and
stability were the outstanding features of the old erection, and were
carried to such an extent as would probably be considered
superfluous in these days. The stone parapet wall would in itself be
an eye-opener to our modern jerrybuilders. Octagonal outside,
circular within, the wall was composed of five courses of Craigleith
freestone, each course feathered and grooved, while each stone
dovetailed its entire depth into its neighbour. At each point of the
octagon holes were drilled from top to bottom of the wall to receive
the two inch iron bolts which secured the heavy cast iron lantern to
the parapet. It was necessary to reduce the stones to fragments
before hurling them into the sea, in order to prevent them
obstructing the boat tracks or damaging the gratings. Between the
outer and inner linings of the copper dome a scrap of newspaper
was found wrapped round what appeared to be a file handle. The
printed matter was quite legible, and bore reference to an
unfortunate episode, happily long since relegated to the realms of
oblivion, namely, the investigation into the conduct of the then
Princess of Wales in 1806. In one of the ventilators which pierced
the parapet wall on a level with the balcony, but long since disused,
a perfectly desiccated specimen of a wren was found. Attracted
probably by the light while on a migratory journey, it had evidently
taken shelter in the ventilating tube just prior to its being plugged up
with a wad of tow, a material which for many years has been
superseded throughout the service by cotton waste.
The ping-pong craze has come our length, and in imitation of
other manlier sports a trophy has been instituted for competition,
the said trophy to become the property of the holder after being
won thirteen consecutive times. The trophy takes the form of a
handsome cup of silver, or, to be more explicit, of a metal usually
found in conjunction with silver, and is quite Grecian in its simplicity
of design. It is considered to be of foreign origin, and bears evidence
of having at one time been profusely chased and engraved. A
beautiful pastoral scene is depicted on the one side, while, on the
other, two foreign words are barely decipherable, namely, “Lait
Concentré.” The trophy generally graces our tea table for some time
prior to the competition, and materially aids in stimulating the
flagging energies of the competitors.
JUNE 1902.

Only towards the end of this month did we experience anything like
summer weather. Belieing the wintry weather we had been
experiencing, the fragrant odour of the hawthorn blossom borne on
the off-shore wind imparts a pleasurable sensation, recalling scenes
of earlier days when void of care we went “flourish” gathering, or
later on disported ourselves amongst the “hips and haws.” Here, no
sylvan scenery greets the tired eye nor gives respite to the senses
from the everlasting waste of waters, with its ever-changing moods,
from placid glassy calm to the wildest turbulence, when blustering
Boreas drives his team amain, and the white-maned coursers charge
down upon us like an avalanche. As the tide drops, and the long lush
tangles trail their tattered tops on the surface, a dank heavy odour is
perceptible, scarcely so pleasing to the senses as that of the
“hawthorn bud that opes in the month of May.” Equipped with a
stout stick bearing an iron hook, an hour’s crab-hunting among the
rocks brings one into contact with many forms of life otherwise
unnoticed. Groping underneath a projecting ledge, to ascertain if the
inmate is at home, the eye is arrested by minute nodules of scarlet
jelly pendant from the roof, and destined to become a close imitation
of their terrestrial namesake the anemone, or, in similar situations,
patches of white whelk ova appear like so many grains of wheat
arranged as close as possible to each other.
Recently a solitary instance was noticed of a whelk carrying the
ova attached to the exterior of its own shell. Many different species
of whelks are thus met with, some scarcely distinguishable by the
naked eye. The intrusion of the crab-stick soon betrays the presence
of the crab. Gripping the “cleek” in his claws, he prepares for
resistance by forcing his back against the roof of his domicile with all
the power his crooked legs are capable of. Should he feel himself
being drawn he immediately releases his grip, and, if possible,
“seeks his benmost bore.” Should the cleek find a favourable hold,
such as under the armpit, so to speak, he is soon dislodged, but if
the hole be somewhat crooked it is extremely difficult to move him,
and even then he may make his appearance in sections, as he parts
company with the different members of his body on the slightest
provocation, a proceeding about which he has but little
compunction, as he knows well others will soon sprout in their
places, a convenience which Nature might with advantage have
extended to the genus homo. Poachers, it is stated, have made use
of these crustaceans while “ferretting” rabbits, by sending them into
the burrows with a stump of lighted candle stuck on their backs. One
can fancy the surprise with which “bunny” would stand aghast at
such a fearful apparition.
Scarcely a bird is to be seen in our vicinity at present, nesting
operations calling them elsewhere. A few foraging gannets are seen
daily passing and repassing, catering for their sitting mates on the
Bass Rock. The terns and gulls will probably have their wants
supplied from the shores in the neighbourhood of their nurseries.
The nest of the tern is of the simplest description—a slight
depression on a gravelly beach or grassy mound, or even the bare
surface of a rock is considered sufficient for their purpose, nest-
building, in their estimation, being evidently considered superfluous.
It is surprising that the eggs remain in some of the positions in
which they are deposited. I have frequently set them rolling along
the rock surface by the action of my breath. On their exit from the
egg the young are immediately led by the parents to a shingly
beach, or other place of concealment, where it is extremely difficult
to detect them from their surroundings. Here they are fed with sand-
eels and other small fry till such time as they are able to wing their
way to the fishing grounds themselves, though even then they are
frequently the recipients of the parents’ generosity, their hunting
powers being as yet inadequate to supply their needs.
The work in connection with the alterations here progresses
rapidly, and by the end of next month it is expected but little will be
left undone. To all external appearance the work is already finished,
but the building of the huge lens and revolving machinery, along
with the internal fittings, have yet to be completed.
JULY 1902.

Myriads of medusae or jellyfishes are constantly streaming past our


door, apparently without any powers of volition of their own, but
helplessly at the mercy of the tides. Of various sizes, shapes, and
colours, they impart quite a gay appearance to the seascape,
somewhat resembling a grassy sward carpeted with beautiful
flowers—huge sunflowers predominating—the whole moving silently
just beneath the green, glassy surface. Great tremulous discs, twelve
inches in diameter, trail their streaming tentacles several feet behind
them; others, again, no larger than a pea possess the power of
radiating, from the ciliary bands with which they are furnished, all
the colours of the rainbow. Stranded high and dry, what a contrast
to their former glory, now an inert mass of slobbery mucilage. At one
period of their existence they appear quite plant-like in their habits.
Attached to the rocks, they closely resemble miniature fir trees, each
plant ultimately producing whole colonies of juvenile medusae. Fish
have been fairly plentiful this month, but owing to the work at
present in progress we have but little time to avail ourselves of the
opportunity. On the 6th a red chequered pigeon, stamped “J. B.
Sollaway, Beeston,” on wing, was released after a night’s detention.
On Saturday the 12th, other two pigeons were captured at 8.30 p.m.
One a red chequered homer, with aluminium ring on leg marked
N.U. 01, H.A. 587, also rubber racing ring on other leg, marked 132
outside and 263 Q inside; the other a blue chequered homer, with
leg ring marked N.U. 99, C. 8953, and racing ring marked Q 513
inside and 174 outside; wing feathers stamped “Walter H. Walker,
Bank House, Horsforth, Leeds.” Both pigeons, after being watered
and fed, were released at 11 a.m. on 13th, each steering a sou’-
westerly course from the Rock.
On the evening of Sunday the 27th our new light was exhibited
for the first time, the coveted honour of “first light” falling in the
ordinary routine of duty to the writer. The new apparatus—a
bewildering arrangement of massive glass prisms—is in striking
contrast with its predecessor, the old reflector system of lighting, a
system, by the way, now almost obsolete. The following description
of the new light is copied from an engraved plate affixed to the new
apparatus:—“Combined hyper-radiant and 1st order apparatus, with
equiangular dioptric elements and catadioptric back prisms; power of
red flash and white flash equalised. White and red flashing light,
showing white and red flashes alternately every half minute, the
period being one minute. Designed by Messrs Stevenson, Civil
Engineers, Edinburgh. Contractors, Messrs Steven & Struthers,
Glasgow, and Messrs Société Des Etablissements Henry Lepaute,
Paris. David A. Stevenson, Engineer to the Board. Apparatus makes
one revolution in one minute—1901.”
Occasionally during the progress of the alterations our population,
unlike that of Arbroath, increased to a somewhat alarming extent,
mounting at times to a grand total of seven all told. Considering that
the majority of the population were unaccustomed to life under such
“cribbed, cabined, and confined” conditions, it was surprising to
witness the cheerfulness and good humour with which they accepted
their sixteen weeks’ solitary confinement. At times the resources of
our commissariat were taxed to their utmost. Beef, which is stored in
our safe on the balcony, and retains its freshness for a fortnight in
cold weather, demands a liberal salting at present, otherwise it does
become a trifle “gamey,” but, on the whole, it is preferable to its
relative in tins—a relationship, by the way, extremely difficult to
prove, and hopelessly so should the label be missing. What though
at times a transverse section of our loaves disclosed a landscape in
cerulean tints undreamt of by the most vivid impressionist, the
transference to “hard tack” was accepted with better grace than
when a similar move had to be made from the salted meat to the
“embalmed commodity.”
AUGUST 1902.

The coating of acorn barnacles with which the higher surfaces of the
Rock and also the base of the tower are whitened in summer is fast
disappearing before the ravages of that ruthless destroyer the white
whelk. Seen from the balcony, this encrustation resembles a lime-
hauled wall, and presents a suitable background for the observation
of moving objects under water. These barnacles are frequently
mistaken by the casual observer for young limpets, whereas, unlike
the limpet, which moves freely from place to place in quest of
vegetable diet, the moment the young barnacle settles to erect his
limey habitation, he possesses a fixity of tenure which terminates
only with his existence. An outer wall, with razor edges, surrounds a
hollow cone, his private apartment, and probably guards his four-
leaved door from injury. This opening, through which all business
with the outer world is transacted, is scarcely discernible when
above water; but immediately the tide covers it, the hollow cone is
seen to fall apart in four vertical sections, a bunch of fingers is thrust
forth and rhythmic clutches made at invisible food. How little they
resemble their relatives who swing by their pendulous stalks from
ships’ bottoms or submerged wreckage, and see the world without
any exertion of their own. The ancients firmly believed that from
these animals certain birds were produced, probably from the
resemblance of their shelly casement to the beak of a bird, and the
bird known as the barnacle-goose owes his name to this belief. Even
to-day there are persons who solemnly declare that the Northern
Diver is so evolved.
Another fallacy common amongst fishing communities on the
West Coast is the attributing the destructive effects of the teredo
navalis, or ship-worm, to the innocent barnacle, whose only fault is
the resistance their multitudes offer to a ship’s progress through the
water. A log of wood which has been adrift at sea for a lengthened
period will generally be found to have its surface clustered with
pendulous barnacles. The removal of these disclose minute pin-holes
on the surface, which, in the interior, assume the diameter of a
man’s little finger, and permeate the log from end to end like a
honeycomb. Each little tunnel is smoothly enamelled with a deposit
of lime by this indefatigable borer, the teredo. Though boring parallel
with his neighbour, the thickness of paper only separating them,
they never, by any chance, encroach on each other’s bore. Their
tracks are seen to abruptly diverge when all but into that of their
neighbour, so that they are evidently cognisant of each other’s
proximity, an interesting fact also apparent in rats on board wooden
vessels, who, though they will gnaw their way through any
woodwork, instinctively refrain from suicidal attempts on the outer
skin of the ship.
On the memorable 9th we had a bird’s-eye view of the Coronation
celebrations in Arbroath. With the aid of our telescope the crowds on
the Common were clearly visible, the ladies in white dresses being
most conspicuous. The flash of the guns firing the royal salute was
seen fifty-five seconds before the report reached us. In the
afternoon the sports in the Victoria Park occupied our attention, and
the white-clad competitors in the high jump could be seen taking
their preliminary run and rising over the obstacle. Parties straying on
the beach had only their heads visible, and as they neared the
margin appeared to vanish under water. The progress of the bonfire
on the Common at night was also watched, and the moving figures
could be plainly seen silhouetted in the glare. Probably but few
noticed our attempt to celebrate the occasion. Two strings of flags
from the balcony to the rocks fluttered gaily in the breeze, while the
balcony railing was similarly decked. Amongst those suspended from
the rail was a flag of peculiar interest, namely, one which had been
sewn by Miss Stevenson, a sister of the builder, Robert Stevenson,
almost a hundred years ago. The central subject depicted on the
white ground is the Bell Rock Lighthouse; on the right, the patron
saint of Scotland with his cross; while a ship under full sail occupies
the left, the whole bordered with a deep edging of red. The figures
are extremely well executed, and the colouring to the flesh tints
remarkable. The flag was presented to the Rock by Miss Stevenson
to be used as a table draping during divine service.
Several white butterflies and moths innumerable were seen
passing here this month. It seems these insects have their migratory
periods as well as birds, and at stations favourable for their
observation they appeared, to quote from a writer in a recent
number of “Chambers’s,” “as a dense snowstorm driven by a light
breeze, and this not for one day only, but for many in succession.
Whereas birds come and go with clockwork regularity, the
immigration of butterflies is uncertain, and of all those which survive
the perils of the deep no single one returns.”
SEPTEMBER 1902.

A good deal of heavy weather has been experienced on the Rock this
month, and the stability of our new lantern subjected to a fair strain,
though probably nothing to what it will have to encounter during the
course of the winter. The lantern—composed of gun metal astragals,
narrowed to the utmost limit compatible with strength, in order to
intercept as little light as possible—may be looked upon as a huge
hollow cylinder of glass, which in itself seems but a feeble barrier to
the onslaughts of the storm. But the three tiers of triangular panes
are of heavy plate glass, and the apparently slim like astragals are
braced together in the most effective manner to ensure the greatest
degree of strength, and need cause no uneasiness to the stranger
viewing the outlook during the progress of a gale. It is awful to think
that out in that dark void, amid the warring elements, fellow beings
may be battling for their lives in close proximity to where we sit in
comfort and security, totally ignorant of their condition, and utterly
helpless to render them the slightest assistance. Probably a case in
point occurred during the gale of the 3rd. On the 9th, about noon,
we were somewhat surprised to see the gunboat Seamew
approaching the Rock with a hoist of flags, indicating that they
wished to communicate with us. Bringing up close to the Rock, they
signalled, “Have you seen a vessel in distress?” to which we
answered “No”; and then remembering we had seen a torpedo boat
pass the day previous, and fearing another case of “buckling” had
occurred, we asked “Was it a torpedo boat?” in reply to which they
communicated the intelligence, “No; it is a sailing craft from
Anstruther last Wednesday, and seven hands.” On our replying “We
have not seen her,” the signal “Thank you” was hoisted, and the
gunboat steamed out to the eastward on her sorrowful quest.
Passing a torpedo boat at gun practice, she was seen to signal her
also, with the difference that the flags then used had no existence in
our code. Later in the evening she was again seen making for
Dundee.
We have had several takes of fish of late, though there seems to
be a scarcity of “fry” compared with last year, the absence of which
probably accounts for the terns failing to call upon us with their
young for a few weeks’ feasting prior to commencing their migratory
journey southwards. Gannets may be seen at present striking at fish
within a few feet of our doorway, while a flock of young gulls hover
expectantly, with feeble peeping cries anticipating the feast in store
for them when the dinner scraps make their appearance. Further off
a few eider ducks—who only arrived on the 25th, somewhat later
than last year—evidently eye the proceedings of these juvenile
degenerates with disdain, preferring to refrain from such pampered
luxuries and dine on the products of the chase alone. The eiders
present are as yet all adult males, the females presumably still
occupied with family cares teaching the young idea how to shoot, or
rather fish, if plucking mussels, catching crabs, etc., can be called so,
for such is their diet, and does not include fish. Strange that the
foremost arrivals among migratory birds are all males. Why this is so
is not agreed upon by observers, some supposing that the females
are detained by maternal duties; others, again, affirm that they
migrate en masse, and that the more vigorous males soon outstrip
and ungallantly leave the gentler sex to bring up the rear. On the 6th
we had our first intimation of the autumnal migratory flight in the
arrival of a flock of wheatears, accompanied by a solitary wren. On
the 27th several greenfinches, larks, and starlings were making
insane efforts to follow the line of most resistance, resulting in our
new lantern receiving its first baptism of blood, as the glass next
morning testified. Several porpoises are to be seen puffing and
blowing a mile off, and on the 28th a school of “finner” whales were
seen heading north.
I see by the Arbroath Guide that one of our old fog bells has been
presented by our Commissioners to the Arbroath Museum, a fit
resting place after its long sojourn on the Rock. Should the date
upon it happen by any chance to become erased, what possible
controversies it may yet become the subject of amongst posterity as
to its connection with that mythical personage “Ralph the Rover.” I
myself can testify to its having conformed in one respect at least
with that of the poem, for on lowering it from its position on the
balcony for shipment the tide had overflowed the Rock about a
couple of feet, causing the bell to settle with an audible gurgle, or as
one of the seamen (Fraser) appropriately quoted, “The bell sank
down with a gurgling sound.”
OCTOBER 1902.

We have had occasional visits of feathered migrants during the


month, but it is a matter of remark that each year sees a decrease in
the number of arrivals here. Probably the increased number of lights
on our coast accounts for this diminution, some proving more
attractive than ours. A few years ago it was quite on the cards at
this season of the year—thanks to the migratory instinct—to have an
additional course at dinner, to which fieldfares, blackbirds, and
redwings were the voluntary contributors, and even at times the
gamey woodcock “graced the groaning board”—for our “board,”
being double-leaved and somewhat senile, does occasionally groan,
and this without reference to any superincumbent strain. Amongst
the more noteworthy of our captures here, at various times, the
following may be mentioned:—A peregrine falcon, large horned owl,
small brown owl, kestrels, sparrow hawks, crows, cormorants, corn-
crakes, and a turtle dove. Birds generally arrive here in a fagged
condition, and are easily captured. As an instance, a kestrel landed
on our balcony railing during fog, and, despite the explosions of our
fog-signal twenty feet overhead, tucked his head under his wing and
fell sound asleep. Another arrival of note was a common blue
pigeon, which, after a few hours’ stay, surprised us by depositing an
egg in our doorway. Disturbed on our appearance, it reluctantly
deserted its treasure, but not without many backward glances before
spreading its wings shorewards.
Podley-fishing has been fairly successful during the month, and
several codlings have been taken from the pools at low water. Whilst
photographing lately, another of our number was busy endeavouring
to extract a breakfast from Port Hamilton. Hooking a fair sized
codling, the camera was turned on the scene, and fish à la photo
figured in our bill of fare next morning. A few years ago a photo was
taken of a paidle cock and hen, both of which were taken from their
nests for this purpose, and proved amenable sitters; the cock
appearing in the photo quite conscious of his importance, though the
hen appeared somewhat bored, having been snapped in the middle
of a huge “gape,” which some of my previous sitters might interpret
as a yawn. Both were returned to their nests none the worse of their
unique experience, and possibly yet relate their feelings before the
camera to the admiring wonder of fishy audiences, till puffed with
the idea of their own importance they now probably suffer from a
disease (peculiar to some higher vertebrates with as slender a
reputation) resulting in what is colloquially known as “swelled head.”
Wouldn’t the fishermen of Arbroath fancy their lines had fallen in
pleasant places should the fish they pursue at such hazard come
sailing voluntarily into the harbour, and even without the usual
ceremony of dropping them a line, appear on the surface, mutely
asking to be lifted out? Such, however, was our experience lately.
Shortly before daybreak one quiet morning our attention was
attracted by the movements of a few gulls, evidently interested in
some object in the water at the edge of the reef. As daylight
advanced it was seen to be a large fish wobbling erratically upon the
surface. On extinguishing the light and descending to the rocks,
which the advancing tide had not yet covered, the fish was seen to
have entered the Johnny Gray boat track, and was propelling itself,
keel upwards, in our direction. A fish in this unusual position
indicates an abnormal distension of the swimming bladder, which, by
over-increasing its buoyancy, entirely upsets its centre of gravity, and
forces it topsy-turvy to the surface. A steam trawler, which had been
working close to the Rock for several days previous, was probably
responsible for our friend’s “blown” condition. Stepping gingerly over
beds of white whelks as we wade bare foot to welcome our visitor,
we mentally contrast our inferiority with more juvenile days—a time
when even road metal could be safely negotiated. The screaming
gulls resent our interference with their expected feast, no doubt
slanging us unmercifully as we land our capture, an arm-long lythe,
safely on the grating. Their clamouring, however, is soon stilled, as
each retires with as big a share of the offal as his strength and
agility can command.
The long-tailed ducks are now only wanting to complete the list of
our winter boarders, and their advent may be looked for early next
month. The eiders have now attained their numerical strength for
the winter, and are busily engaged picking up a living, not only for
themselves, but also for the parasitical gulls which hover in close
attendance, shepherding them with unwearied diligence. The
peculiar cackling of the eiders—not unlike that of wild geese—
becomes somewhat disturbing as their operations are occasionally
carried on underneath our bedroom window. Gannets are now rarely
seen here, but at their breeding haunts on the Bass Rock—which we
had the opportunity of visiting while on our way here last relief—
they are still in evidence, though by the end of the month they will
have commenced their journey southwards. A new light is being
completed on the Bass Rock, and on the first of December, yet
another factor in our dwindling list of visitors will be in operation—
ostensibly a lighthouse—but to our feathered friends, alas! a
veritable slaughter-house.
NOVEMBER 1902.

Exceedingly stormy weather, with a prevalence of sou’-easterly winds


and heavy seas, has been our portion here this month, restricting
our movements out of doors, till with circling round our promenade
on the balcony one almost doubts the possibility of ever again being
able to hold a straight course when opportunity offers. Workmen
have been engaged this month fitting up a service of copper piping
from the grating at the base of the tower to the cisterns in the oil
store on the third flat, whereby the operation of storing oil will in
future be rendered much easier. The oil will now be landed in forty-
gallon casks, instead of the small six-gallon ankers as formerly,
emptied into a sifting tank on the grating, and by means of a rotary
pump forced upwards to the oil cisterns—a vast improvement on the
old system, when each anker had to be hoisted indoors, and then
shouldered upstairs to the cisterns.
A pleasing incident of the month was the arrival of a handsome
present for each of the keepers, consisting of a silver mounted briar
pipe, a pound of golden bar tobacco, and a liberal supply of first
class reading matter. All keepers throughout the service—over 200—
were similarly supplied, so that the gift will be seen to be a pretty
extensive one, and the donor, James Coats, junr., Paisley, has
without doubt earned the gratitude of the service by this generous
act of kindness.
About the beginning of the month we had a few feathered
visitors, chiefly blackbirds, fieldfares, and starlings. On the morning
of the 5th several struck heavily on the lantern, but were swept
away by the strong sou’-east wind then blowing. The gannets have
now all disappeared, none having been seen since the 27th. The
eiders continue in close attendance and have had their numbers
augmented by the arrival of the longtails on the 9th, a week earlier
than last year, thus completing our list of regular boarders for the
winter. At 6 p.m. on the 13th we were privileged with the unusual
spectacle of a lunar rainbow. The bow—a faint white arc against the
dark background—was distinctly visible in the nor’-west, though, of
course, void of the vivid colouring inseparable from its solar
namesake.
While taking a turn round the balcony on the evening of the 15th,
our attention was attracted to what appeared to be a peculiar
shaped mass of foam resting on the rocks immediately beneath us.
On careful observation, however, the object was seen to move
slightly in the faint moonlight, and by the aid of our telescope the
outline of a seal could be dimly seen. On the change of the watch at
6 p.m. an attacking party, including the workmen then on the Rock,
was organised, and a plan of campaign drawn up. Descending the
outside ladder, which was fortunately in deep shadow, we were able
to gain a footing on the Rock unperceived. His suspicions had,
however, evidently been aroused, as he was seen to lift his head
sniffing uneasily in our direction. Bracing ourselves within the margin
of the shadow cast by the tower, we charged down upon him at the
double, expecting to see him beat a hasty retreat to the water; but,
to our surprise, he made no effort whatever in that direction, but
seemed to consider himself quite a match for us, and that there was
no present necessity for retreating. Snarling and snapping viciously
as we surrounded him, he appeared at a great disadvantage
compared with his agile movements when in his element, his hind
flippers being now of practically little use to him, his lumbering
movements being effected by the aid of the fore flippers alone. His
furious efforts to sample portions of our anatomy were easily
avoided, and by laying hold of his hind flippers, as one would trundle
a barrow, he was immediately placed hors-de-combat. An
unfortunate squid or cuttlefish, which had been left stranded by the
receding tide, when pushed within his reach was seized and
energetically shaken with all the vim of an accomplished ratter. The
wooden shaft of a boat-hook was similarly treated, and still bears
evidence of his utter ignorance of the dental profession. A rope
being procured, a clove hitch was slipped over one of his hind-
flippers, the other end made fast to an eye-bolt on the Rock. Thus
secured, he was left to his novel reflections for the night.

As the tide covered the Rock he could be seen in the clear


moonlight ploughing along the creamy surface, stretching his tether
in every direction in futile efforts to escape. At daylight next morning
he was found sheltering under a projecting ledge of rock. What a
clean, well-groomed fellow he looked, with his sleek, glossy coat
glistening in the sunshine, his squat, plump body adapting itself to
the inequalities of the surface on which it rested. His coat, by the
way, as much fur as that of a horse—grey above, mottled with dark
spots, while the under surface is of a creamy yellow. His beautiful
teeth gleaming white against the scarlet interior of his mouth, as he
snapped fruitlessly on either side, suggested the maximum of robust
animal health. As a memento of his visit the camera was brought on
the scene, and another addition made to our list of illustrious
visitors.
Liberating him proved to be more difficult than his capture, for
when cut adrift he persisted in facing us instead of making for the
water, towards which we endeavoured to drive him. After some
manœuvring, however, he was driven to the edge of the gulley, but
even with his body half submerged he maintained a defensive
attitude, not seeming to realise that he was at liberty to depart. An
incoming wave, however, moved him to a sense of his position, and
with a defiant snort he slipped under water. Omitting, in his hurry, to
take proper bearings, he took the wrong direction, and, finding
himself in a cul-de-sac, made his appearance again on the surface,
and with a hurried glance at his position again sank, this time
making a bee-line for the outlet, being clearly seen, as he passed
under water close to where we stood, and was last seen buffeting
his way through the foaming breakers, evidently none the worse for
his compulsory detention on the Rock.
DECEMBER 1902.

The broken stones and other debris, consequent upon the late
alterations here, which had collected in various holes in the Rock and
maintained their position up till now, have nearly all been cleared
out by the severe gales of this month, and a couple of heavy iron
poles, erected lately to mark the boat tracks or entrances to the
landings, and which were sunk two feet in the solid rock and heavily
cemented, have been shaken loose in their sockets by the pounding
seas which have been besieging us of late. The rocks appear bleak
and bare, and utterly void of vegetation. The white whelks have
collected their scattered forces, and gone into winter quarters.
Secure in sheltering nooks, they lie huddled together in close packed
squadrons. Numerous small white banded whelks adhere to the base
of the tower with a tenacity that seems surprising considering the
swirling seas they are subjected to. This species, however, never
seem to dream of hibernating. The eiders and longtails, with an
unswerving attention to business, pursue their calling amid the
hurly-burly of broken, tumbling seas—evidently little concerned
whether the weather be fair or foul—and in the glassy hollows
alternating between the breakers they can be distinctly seen
scurrying over the rock surface like so many fish. Gannets this
month are conspicuous by their absence, and only a few parasitic
gulls divide their attention between the kitchen refuse and the hard
won earnings of the eiders.
On several occasions during the month our fog signal was
brought into action through the occurrence of heavy snowfalls. A
silent, feathery fall on shore no doubt has charms peculiarly its own,
but at sea constitutes a very serious danger to the anxious mariner
as he steams at reduced speed through the fleecy curtain, shrieking
his every two minute warning, his vessel’s head scarcely visible from
the bridge. In snowstorms such as we have had of late our lantern
soon becomes plastered up with snow on the weather side,
necessitating constant removal to prevent it from completely blinding
our light in that direction. This is an operation often accomplished
with difficulty, especially when carried out in the teeth of a gale—an
experience somewhat akin to lying out on a yardarm under similar
conditions, only one doesn’t have the lift and ’scend of the vessel to
contend with; yet his grip must be equally as sure, or, as the old
salts phrase it, “Every finger a fish-hook,” on such occasions.
Mounting by an outside ladder to the grated gallery which encircles
the base of the lantern, one is exposed to the full force of the blast,
and a firm grip must be taken to avoid being blown away. Below, the
seas in wild tumult break against the building with a deafening roar,
sending a perceptible tremor through the entire structure with each
impact. Only by energetically hauling on the hand-rail can the
slightest progress be made in the desired direction, the wind’s eye
being the objective point, where possibly on arrival one may find
himself pinned flat to the lantern, like an entomological specimen, by
the force of the wind. The snow removed, the return journey is
effected by simply allowing oneself to be blown gradually back.
While relieving the Bass Rock on our way ashore last relief, a
good opportunity was afforded of witnessing the mode of effecting a
landing under adverse circumstances. On arrival there, it was
considered dangerous to attempt a landing at either of the two
landing places, owing to the heavy sea then running. The landings—
a flight of concrete steps from the water edge to the rocks above—
are situated on either side of a slight promontory immediately
beneath the lighthouse; and as deep water obtains to the rock face,
it will be obvious that similar conditions must frequently prevail at
either landing. The boat being loaded with the necessary stores, and
the relieving keeper on board, an approach was made to within
suitable distance of the Rock. A kedge anchor was then thrown
overboard, and the boat slacked down till within working distance.
The keepers meanwhile had been busy erecting an iron pole or
derrick on the rocks above the position now occupied by the boat,
and which, being slightly inclined seawards, a tackle from its
extremity was drawn by means of a guy-line to the boat, and the
stores hoisted ashore by the keepers in charge of the tackle-fall
above. Seated in a loop of the rope, the relieving keeper was then
hoisted, and his shore-going neighbour similarly lowered. As an
extra precaution, a second boat was sent from the ship to stand by
the working boat in case of accident. Fortunately, however, their
services were not required.
Our final relief here for the year was effected with some difficulty
on the 29th. Owing to the doubtful aspect of the landing, only one
boat was sent ashore instead of two as usual. The fortnightly supply
of coal and water being omitted on this occasion does not, however,
inconvenience us, as a three months’ reserve stock of necessaries is
always maintained during the winter months.
JANUARY-FEBRUARY 1903.

Bright, sunny weather characterised the opening day of the year, the
sea assuming a suspicious placidity quite summer-like in appearance
but for the keen nip in the air perceptible out of doors. This state of
affairs, however, proved but ephemeral, and for the remainder of the
month we have experienced most boisterous weather. Strong
westerly winds occasionally attained the force of a gale,
accompanied with driving seas, which roared and sang a lullaby
scarcely compatible with the shore-dwellers’ sense of security, but
which, strange to say, has a more somnolent effect upon us than a
breathless stillness, though an occasional thumper of a sea, more
forceful than its fellows, demonstrates the stability of our domicile by
imparting a gentle tremor to the entire structure, awakening in the
sleeper a glimmer of consciousness and a hazy impression of a
traction-engine lumbering somewhere in the vicinity.
Our entrance doorway—thirty feet from the Rock—faces south-
west, and is guarded by a heavy double leaved door, which opens
outwards, and held open against the building by means of heavy
brass thumb-snecks. An inner or vestibule door of solid brass is
placed six feet further inwards—the walls here, by the way, being
seven feet thick, tapering to one foot immediately beneath the
balcony, sixty feet higher up. This door is also double-leaved, with
the upper panels of heavy plate glass, frequently obscured by the
strong westerly wind whipping the tops of the seas as they rise in
front, and carrying them souse into the doorway. Standing here
during the prevalence of a gale, the outlook is being constantly
darkened by a curtain of hissing foam drawn across the doorway, as
each sea breaks against the base of the tower, flinging the spray
high overhead. Fifteen miles in front of us lies the Isle of May, with
its castle-like lighthouse crowning its summit, while on a lower level
stands a whitewashed relic—remnant of a time, not so long ago,
when the Island boasted a double light, and electricity had not as
yet usurped sole sway. Emerging from the right of the May appears
the bluff outline of the Bass Rock, while away in the far distance
North Berwick Law cleaves the sky-line. Away to St Abb’s Head, on
the left, the Haddington coast stretches hazy and indistinct, while
the green, grassy slopes of Fife, with the spires of St Andrews faintly
visible, fill in the right of the picture. Laying hold of the man-ropes
suspended in the doorway, and turning to the right, the Forfarshire
coast is seen extending from the Tay in a long unbroken line, with
the snow-clad Grampians towering majestically in the background.
Right in front of us are the smoking stalks of Arbroath. Two
conspicuous white dots in the foreground mark the pierheads, in
front of which an impatient “flaxer” cruises in glorious uncertainty of
ever being permitted to fulfil her charter and deposit her Riga-run
freight on the right side of the bar. This is the panorama from the
viewpoint of our doorway on a clear day, but, as seen of late
through sheets of flying foam, it reminds one of a cinematograph
display, in which the films are far from perfect.
On the first Sunday of the year hundreds of gulls were seen
resting on the surface of the sea, half a mile nor’-west from here,
evidently by their movements enjoying a feast of “fry,” and in all
probability proclaiming the presence of herring shoals. During the
gale of 10th January over a dozen gannets were seen swooping and
diving, presumably at herring. Only with difficulty could we maintain
our position on the balcony, owing to the force of the wind, yet
these birds circled and dived amid the turmoil of wind and water
with a graceful ease and precision that seemed truly wonderful
considering the force of wind they occasionally beat up against, or,
as they turned broadside on, were wafted without the least exertion
in the opposite direction. The first week of February saw hundreds of
these birds back to their breeding haunts on the Bass Rock. From
the deck of the “Relief” steamer lying within a few hundred yards
their movements are clearly seen. Each projecting ledge of the
precipitous cliffs is tenanted by some members of the cackling

You might also like