You are on page 1of 54

Modern C++ for Absolute Beginners: A

Friendly Introduction to C++


Programming Language and C++11 to
C++20 Standards 1st Edition Slobodan
Dmitrovi■
Visit to download the full and correct content document:
https://textbookfull.com/product/modern-c-for-absolute-beginners-a-friendly-introducti
on-to-c-programming-language-and-c11-to-c20-standards-1st-edition-slobodan-dmitr
ovic/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Modern C++ for Absolute Beginners: A Friendly


Introduction to C++ Programming Language and C++11 to
C++20 Standards 1st Edition Slobodan Dmitrovi■

https://textbookfull.com/product/modern-c-for-absolute-beginners-
a-friendly-introduction-to-c-programming-language-
and-c11-to-c20-standards-1st-edition-slobodan-dmitrovic/

Modern C for Absolute Beginners A Friendly Introduction


to the C Programming Language Slobodan Dmitrovi■

https://textbookfull.com/product/modern-c-for-absolute-beginners-
a-friendly-introduction-to-the-c-programming-language-slobodan-
dmitrovic/

Modern C for Absolute Beginners A Friendly Introduction


to the C Programming Language Dmitrovi■ Slobodan

https://textbookfull.com/product/modern-c-for-absolute-beginners-
a-friendly-introduction-to-the-c-programming-language-dmitrovic-
slobodan/

Modern C for Absolute Beginners: A Friendly


Introduction to the C Programming Language 2nd Edition
Slobodan Dmitrovi■

https://textbookfull.com/product/modern-c-for-absolute-beginners-
a-friendly-introduction-to-the-c-programming-language-2nd-
edition-slobodan-dmitrovic/
Handbook of Macroeconomics, Volume 2A-2B SET 1st
Edition John B. Taylor

https://textbookfull.com/product/handbook-of-macroeconomics-
volume-2a-2b-set-1st-edition-john-b-taylor/

Modern C for Absolute Beginners 1st Edition Slobodan


Dmitrovic

https://textbookfull.com/product/modern-c-for-absolute-
beginners-1st-edition-slobodan-dmitrovic/

Modern C++ for Absolute Beginners 1st Edition Slobodan


Dmitrovi■ [Dmitrovi■

https://textbookfull.com/product/modern-c-for-absolute-
beginners-1st-edition-slobodan-dmitrovic-dmitrovic/

C# Programming for Absolute Beginners Radek Vystav■l

https://textbookfull.com/product/c-programming-for-absolute-
beginners-radek-vystavel/

Modern C for Absolute Beginners - Second Edition


Solbodan Dmitrovic

https://textbookfull.com/product/modern-c-for-absolute-beginners-
second-edition-solbodan-dmitrovic/
Slobodan Dmitrović

Modern C++ for Absolute Beginners


A Friendly Introduction to C++ Programming
Language and C++11 to C++20 Standards
1st ed.
Slobodan Dmitrović
Belgrade, Serbia

Any source code or other supplementary material referenced by the


author in this book is available to readers on GitHub via the book’s
product page, located at www.​apress.​com/​9781484260463. For more
detailed information, please visit http://​www.​apress.​com/​source-code.

ISBN 978-1-4842-6046-3 e-ISBN 978-1-4842-6047-0


https://doi.org/10.1007/978-1-4842-6047-0

© Slobodan Dmitrović 2020

This work is subject to copyright. All rights are reserved by the


Publisher, whether the whole or part of the material is concerned,
specifically the rights of translation, reprinting, reuse of illustrations,
recitation, broadcasting, reproduction on microfilms or in any other
physical way, and transmission or information storage and retrieval,
electronic adaptation, computer software, or by similar or dissimilar
methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

Distributed to the book trade worldwide by Apress Media, LLC, 1 New


York Plaza, New York, NY 10004, U.S.A. Phone 1-800-SPRINGER, fax
(201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit
www.springeronline.com. Apress Media, LLC is a California LLC and the
sole member (owner) is Springer Science + Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
To M. R., whose work is an inspiration to me.
Acknowledgments
I would like to thank my friends and fellow C++ peers who have
supported me in writing this book.
I owe my gratitude to outstanding professionals at Apress for their
amazing work and support during the entire writing and production
process.
I am thankful to the StackOverflow and the entire C++ community
for their help and feedback.
My deepest appreciation goes to S. Antonijević, Jovo Arežina, and
Saša Popović for their ongoing support.
Table of Contents
Chapter 1:​Introduction
Chapter 2:​What is C++?​
2.​1 C++ Standards
Chapter 3:​C++ Compilers
3.​1 Installing C++ Compilers
3.​1.​1 On Linux
3.​1.​2 On Windows
Chapter 4:​Our First Program
4.​1 Comments
4.​2 Hello World Example
Chapter 5:​Types
5.​1 Fundamental Types
5.​1.​1 Boolean
5.​1.​2 Character Type
5.​1.​3 Integer Types
5.​1.​4 Floating-Point Types
5.​1.​5 Type void
5.​2 Type Modifiers
5.​3 Variable Declaration, Definition, and Initialization
Chapter 6:​Exercises
6.​1 Hello World and Comments
6.​2 Declaration
6.​3 Definition
6.​4 Initialization
Chapter 7:​Operators
7.​1 Assignment Operator
7.​2 Arithmetic Operators
7.​3 Compound Assignment Operators
7.​4 Increment/​Decrement Operators
Chapter 8:​Standard Input
Chapter 9:​Exercises
9.​1 Standard Input
9.​2 Two Inputs
9.​3 Multiple Inputs
9.​4 Inputs and Arithmetic Operations
9.​5 Post-Increment and Compound Assignment
9.​6 Integral and Floating-point Division
Chapter 10:​Arrays
Chapter 11:​Pointers
Chapter 12:​References
Chapter 13:​Introduction to Strings
13.​1 Defining a String
13.​2 Concatenating Strings
13.​3 Accessing Characters
13.​4 Comparing Strings
13.​5 String Input
13.​6 A Pointer to a String
13.​7 Substrings
13.​8 Finding a Substring
Chapter 14:​Automatic Type Deduction
Chapter 15:​Exercises
15.​1 Array Definition
15.​2 Pointer to an Object
15.​3 Reference Type
15.​4 Strings
15.​5 Strings from Standard Input
15.​6 Creating a Substring
15.​7 Finding a single Character
15.​8 Finding a Substring
15.​9 Automatic Type Deduction
Chapter 16:​Statements
16.​1 Selection Statements
16.​1.​1 if Statement
16.​1.​2 Conditional Expression
16.​1.​3 The Logical Operators
16.​1.​4 switch Statement
16.​2 Iteration Statements
16.​2.​1 for Statement
16.​2.​2 while Statement
16.​2.​3 do Statement
Chapter 17:​Constants
Chapter 18:​Exercises
18.​1 A Simple if-statement
18.​2 Logical Operators
18.​3 The switch-statement
18.​4 The for-loop
18.​5 Array and the for-loop
18.​6 The const Type Qualifier
Chapter 19:​Functions
19.​1 Introduction
19.​2 Function Declaration
19.​3 Function Definition
19.​4 Return Statement
19.​5 Passing Arguments
19.​5.​1 Passing by Value/​Copy
19.​5.​2 Passing by Reference
19.​5.​3 Passing by Const Reference
19.​6 Function Overloading
Chapter 20:​Exercises
20.​1 Function Definition
20.​2 Separate Declaration and Definition
20.​3 Function Parameters
20.​4 Passing Arguments
20.​5 Function Overloads
Chapter 21:​Scope and Lifetime
21.​1 Local Scope
21.​2 Block Scope
21.​3 Lifetime
21.​4 Automatic Storage Duration
21.​5 Dynamic Storage Duration
21.​6 Static Storage Duration
21.​7 Operators new and delete
Chapter 22:​Exercises
22.​1 Automatic Storage Duration
22.​2 Dynamic Storage Duration
22.​3 Automatic and Dynamic Storage Durations
Chapter 23:​Classes - Introduction
23.​1 Data Member Fields
23.​2 Member Functions
23.​3 Access Specifiers
23.​4 Constructors
23.​4.​1 Default Constructor
23.​4.​2 Member Initialization
23.​4.​3 Copy Constructor
23.​4.​4 Copy Assignment
23.​4.​5 Move Constructor
23.​4.​6 Move Assignment
23.​5 Operator Overloading
23.​6 Destructors
Chapter 24:​Exercises
24.​1 Class Instance
24.​2 Class with Data Members
24.​3 Class with Member Function
24.​4 Class with Data and Function Members
24.​5 Class Access Specifiers
24.​6 User-defined Default Constructor and Destructor
24.​7 Constructor Initializer List
24.​8 User-defined Copy Constructor
24.​9 User-defined Move Constructor
24.​10 Overloading Arithmetic Operators
Chapter 25:​Classes – Inheritance and Polymorphism
25.​1 Inheritance
25.​2 Polymorphism
Chapter 26:​Exercises
26.​1 Inheritance
Chapter 27:​The static Specifier
Chapter 28:​Templates
Chapter 29:​Enumerations
Chapter 30:​Exercises
30.​1 Static variable
30.​2 Static data member
30.​3 Static member function
30.​4 Function Template
30.​5 Class Template
30.​6 Scoped Enums
30.​7 Enums in a switch
Chapter 31:​Organizing code
31.​1 Header and Source Files
31.​2 Header Guards
31.​3 Namespaces
Chapter 32:​Exercises
32.​1 Header and Source Files
32.​2 Multiple Source Files
32.​3 Namespaces
32.​4 Nested Namespaces
Chapter 33:​Conversions
33.​1 Implicit Conversions
33.​2 Explicit Conversions
Chapter 34:​Exceptions
Chapter 35:​Smart Pointers
35.​1 Unique Pointer
35.​2 Shared Pointer
Chapter 36:​Exercises
36.​1 static_​cast Conversion
36.​2 A Simple Unique Pointer:​
36.​3 Unique Pointer to an Object of a Class
36.​4 Shared Pointers Exercise
36.​5 Simple Polymorphism
36.​6 Polymorphism II
36.​7 Exception Handling
36.​8 Multiple Exceptions
Chapter 37:​Input/​Output Streams
37.​1 File Streams
37.​2 String Streams
Chapter 38:​C++ Standard Library and Friends
38.​1 Containers
38.​1.​1 std:​:v
​ ector
38.​1.​2 std:​:a
​ rray
38.​1.​3 std:​:s​ et
38.​1.​4 std:​:m
​ ap
38.​1.​5 std:​:p
​ air
38.​1.​6 Other Containers
38.​2 The Range-Based for Loop
38.​3 Iterators
38.​4 Algorithms and Utilities
38.​4.​1 std:​:s​ ort
38.​4.​2 std:​:f​ ind
38.​4.​3 std:​:c​ opy
38.​4.​4 Min and Max Elements
38.​5 Lambda Expressions
Chapter 39:​Exercises
39.​1 Basic Vector
39.​2 Deleting a Single Value
39.​3 Deleting a Range of Elements
39.​4 Finding Elements in a Vector
39.​5 Basic Set
39.​6 Set Data Manipulation
39.​7 Set Member Functions
39.​8 Search for Data in a Set
39.​9 Basic Map
39.​10 Inserting Into Map
39.​11 Searching and Deleting From a Map
39.​12 Lambda Expressions
Chapter 40:​C++ Standards
40.​1 C++11
40.​1.​1 Automatic Type Deduction
40.​1.​2 Range-based Loops
40.​1.​3 Initializer Lists
40.​1.​4 Move Semantics
40.​1.​5 Lambda Expressions
40.​1.​6 The constexpr Specifier
40.​1.​7 Scoped Enumerators
40.​1.​8 Smart Pointers
40.​1.​9 std:​:u
​ nordered_​set
40.​1.​10 std:​:u
​ nordered_​map
40.​1.​11 std:​:t​ uple
40.​1.​12 static_​assert
40.​1.​13 Introduction to Concurrency
40.​1.​14 Deleted and Defaulted Functions
40.​1.​15 Type Aliases
40.​2 C++14
40.​2.​1 Binary Literals
40.​2.​2 Digits Separators
40.​2.​3 Auto for Functions
40.​2.​4 Generic Lambdas
40.​2.​5 std:​:m
​ ake_​unique
40.​3 C++17
40.​3.​1 Nested Namespaces
40.​3.​2 Constexpr Lambdas
40.​3.​3 Structured Bindings
40.​3.​4 std:​:f​ ilesystem
40.​3.​5 std:​:s​ tring_​view
40.​3.​6 std:​:a
​ ny
40.​3.​7 std:​:v
​ ariant
40.​4 C++20
40.​4.​1 Modules
40.​4.​2 Concepts
40.​4.​3 Lambda Templates
40.​4.​4 [likely] and [unlikely] Attributes
40.​4.​5 Ranges
40.​4.​6 Coroutines
40.​4.​7 std:​:s​ pan
40.​4.​8 Mathematical Constants
Summary and Advice
The go-to Reference
StackOverflow
Other Online Resources
Other C++ Books
Advice
Index
About the Author
Slobodan Dmitrović
is a software development consultant
and an author from Serbia. He
specializes in C++ training, technical
analysis, and software architecture. He is
a highly visible member of the SE
European C++ community and a
StackOverflow contributor. Slobodan has
gained international experience working
as a software consultant in Denmark,
Poland, Croatia, China, and the
Philippines. Slobodan maintains a
website at www.cppandfriends.com
.
About the Technical Reviewer
Chinmaya Patnayak
is an embedded software developer at
NVIDIA and is skilled in C++, CUDA, deep
learning, Linux, and file systems. He has
been a speaker and instructor for deep
learning at various major technology
events across India. Chinmaya holds an
M.Sc. degree in physics and B.E. in
electrical and electronics engineering
from BITS Pilani. He has previously
worked with Defence Research and
Development Organization (DRDO) on
encryption algorithms for video streams.
His current interest lies in neural
networks for image segmentation and applications in biomedical
research and self-driving cars. Find more about him at
chinmayapatnayak.github.io.
© Slobodan Dmitrović 2020
S. Dmitrović, Modern C++ for Absolute Beginners
https://doi.org/10.1007/978-1-4842-6047-0_1

1. Introduction
Slobodan Dmitrović 1
(1) Belgrade, Serbia

Dear Reader,
Congratulations on choosing to learn the C++ programming
language, and thank you for picking up this book. My name is Slobodan
Dmitrović, I am a software developer and a technical writer, and I will
try to introduce you to a beautiful world of C++ to the best of my
abilities.
This book is an effort to introduce the reader to a C++ programming
language in a structured, straightforward, and friendly manner. We will
use the “just enough theory and plenty of examples” approach
whenever possible.
To me, C++ is a wonderful product of the human intellect. Over the
years, I have certainly come to think of it as a thing of beauty and
elegance. C++ is a language like no other, surprising in its complexity,
yet wonderfully sleek and elegant in so many ways. It is also a language
that cannot be learned by guessing, one that is easy to get wrong and
challenging to get right.
In this book, we will get familiar with the language basics first.
Then, we will move onto standard-library. Once we got these covered,
we will describe the modern C++ standards in more detail.
After each section, there are source code exercises to help us adopt
the learned material more efficiently. Let us get started!
© Slobodan Dmitrović 2020
S. Dmitrović, Modern C++ for Absolute Beginners
https://doi.org/10.1007/978-1-4842-6047-0_2

2. What is C++?
Slobodan Dmitrović 1
(1) Belgrade, Serbia

C++ is a programming language. A standardized, general-purpose,


object-oriented, compiled language. C++ is accompanied by a set of
functions and containers called the C++ Standard-Library. Bjarne
Stroustrup created C++ as an extension to a C programming language.
Still, C++ evolved to be a completely different programming language.
Let us emphasize this: C and C++ are two different languages. C++
started as “C with classes,” but it is now a completely different language.
So, C++ is not C; C++ is not C with classes; it is just C++. And there is no
such thing as a C/C++ programming language.
C++ is widely used for the so-called systems programming as well as
application programming. C++ is a language that allows us to get down
to the metal where we can perform low-level routines if needed, or soar
high with abstraction mechanisms such as templates and classes.

2.1 C++ Standards


C++ is governed by the ISO C++ standard. There are multiple ISO C++
standards listed here in chronological order: C++03, C++11, C++14,
C++17, and the upcoming C++20 standard.
Every C++ standard starting with the C++11 onwards is referred to
as “Modern C++.” And modern C++ is what we will be teaching in this
book.
© Slobodan Dmitrović 2020
S. Dmitrović, Modern C++ for Absolute Beginners
https://doi.org/10.1007/978-1-4842-6047-0_3

3. C++ Compilers
Slobodan Dmitrović 1
(1) Belgrade, Serbia

C++ programs are usually a collection of C++ code spread across one or
multiple source files. The C++ compiler compiles these files and turns
them into object files. Object files are linked together by a linker to
create an executable file or a library. At the time of the writing, some of
the more popular C++ compilers are:
– The g++ frontend (as part of the GCC)
– Visual C++ (as part of the Visual Studio IDE)
– Clang (as part of the LLVM)

3.1 Installing C++ Compilers


The following sections explain how to install C++ compilers on Linux
and Windows and how to compile and run our C++ programs.

3.1.1 On Linux
To install a C++ compiler on Linux , type the following inside the
terminal:

sudo apt-get install build-essential

To compile the C++ source file source.cpp, we type:

g++ source.cpp
This command will produce an executable with the default name of
a.out. To run the executable file, type:

./a.out

To compile for a C++11 standard, we add the -std=c++11 flag:

g++ -std=c++11 source.cpp

To enable warnings, we add the -Wall flag:

g++ -std=c++11 -Wall source.cpp

To produce a custom executable name, we add the -o flag followed


by an executable name:

g++ -std=c++11 -Wall source.cpp -o myexe

The same rules apply to the Clang compiler. Substitute g++ with
clang++.

3.1.2 On Windows
On Windows , we can install a free copy of Visual Studio.
Choose Create a new project, make sure the C++ language option is
selected, and choose - Empty Project – click Next and click Create. Go to
the Solution Explorer panel, right-click on the project name, choose
Add – New Item – C++ File (.cpp), type the name of a file (source.cpp),
and click Add. Press F5 to run the program.
We can also do the following: choose Create a new project, make
sure the C++ language option is selected, and choose – Console App –
click Next and click Create.
If a Create a new project button is not visible, choose File – New –
Project and repeat the remaining steps.
© Slobodan Dmitrović 2020
S. Dmitrović, Modern C++ for Absolute Beginners
https://doi.org/10.1007/978-1-4842-6047-0_4

4. Our First Program


Slobodan Dmitrović 1
(1) Belgrade, Serbia

Let us create a blank text file using the text editor or C++ IDE of our
choice and name it source.cpp. First, let us create an empty C++
program that does nothing. The content of the source.cpp file is:

int main(){}

The function main is the main program entry point, the start of our
program. When we run our executable, the code inside the main
function body gets executed. A function is of type int (and returns a
result to the system, but let us not worry about that just yet). The
reserved name main is a function name. It is followed by a list of
parameters inside the parentheses () followed by a function body
marked with braces {}. Braces marking the beginning and the end of a
function body can also be on separate lines:

int main()
{

This simple program does nothing, it has no parameters listed


inside parentheses, and there are no statements inside the function
body. It is essential to understand that this is the main program
signature.
There is also another main function signature accepting two
different parameters used for manipulating the command line
arguments. For now, we will only use the first form .

4.1 Comments
Single line comments in C++ start with double slashes // and the
compiler ignores them. We use them to comment or document the code
or use them as notes:

int main()
{
// this is a comment
}

We can have multiple single-line comments:

int main()
{
// this is a comment
// this is another comment
}

Multi-line comments start with the /* and end with the */. They
are also known as C-style comments. Example:

int main()
{
/* This is a
multi-line comment */
}

4.2 Hello World Example


Now we are ready to get the first glimpse at our “Hello World” example.
The following program is the simplest “Hello World” example. It prints
out Hello World. in the console window:
#include <iostream>

int main()
{
std::cout << "Hello World.";
}
Believe it or not, the detailed analysis and explanation of this
example is 15 pages long. We can go into it right now, but we will be no
wiser at this point as we first need to know what headers, streams,
objects, operators, and string literals are. Do not worry. We will get
there.

A brief(ish) explanation
The #include <iostream> statement includes the iostream
header into our source file via the #include directive. The iostream
header is part of the standard library. We need its inclusion to use the
std::cout object, also known as a standard-output stream. The <<
operator inserts our Hello World string literal into that output stream.
String literal is enclosed in double quotes "". The ; marks the end of
the statement. Statements are pieces of the C++program that get
executed. Statements end with a semicolon ; in C++. The std is the
standard-library namespace and :: is the scope resolution operator.
Object cout is inside the std namespace, and to access it, we need to
prepend the call with the std::. We will get more familiar with all of
these later in the book, especially the std:: part.

A brief explanation
In a nutshell, the std::cout << is the natural way of outputting data
to the standard output/console window in C++.
We can output multiple string literals by separating them with
multiple << operators:

#include <iostream>

int main()
{
std::cout << "Some string." << " Another
string.";
}
To output on a new line, we need to output a new-line character \n
literal. The characters are enclosed in single quotes '\n'.
Example:

#include <iostream>

int main()
{
std::cout << "First line" << '\n' << "Second
line.";
}

The \ represents an escape sequence, a mechanism to output


certain special characters such as new-line character '\n', single
quote character '\'' or a double quote character '\"'.
Characters can also be part of the single string literal:

#include <iostream>

int main()
{
std::cout << "First line\nSecond line.";
}

Do not use using namespace std;


Many examples on the web introduce the entire std namespace into the
current scope via the using namespace std; statement only to be
able to type cout instead of the std::cout. While this might save us
from typing five additional characters, it is wrong for many reasons. We
do not want to introduce the entire std namespace into the current
scope because we want to avoid name clashes and ambiguity. Good to
remember: do not introduce the entire std namespace into a current
scope via the using namespace std; statement. So, instead of this
wrong approach:
#include <iostream>

using namespace std; // do not use this

int main()
{
cout << "A bad example.";
}
use the following:

#include <iostream>

int main()
{
std::cout << "A good example.";
}

For calls to objects and functions that reside inside the std
namespace, add the std:: prefix where needed.
© Slobodan Dmitrović 2020
S. Dmitrović, Modern C++ for Absolute Beginners
https://doi.org/10.1007/978-1-4842-6047-0_5

5. Types
Slobodan Dmitrović 1
(1) Belgrade, Serbia

Every entity has a type. What is a type? A type is a set of possible values
and operations. Instances of types are called objects. An object is some
region in memory that has a value of particular type (not to be confused
with an instance of a class which is also called object).

5.1 Fundamental Types


C++ has some built-in types. We often refer to them as fundamental
types. A declaration is a statement that introduces a name into a
current scope.

5.1.1 Boolean
Let us declare a variable b of type bool . This type holds values of
true and false.

int main()
{
bool b;
}

This example declares a variable b of type bool. And that is it. The
variable is not initialized, no value has been assigned to it at the time of
construction. To initialize a variable, we use an assignment operator =
followed by an initializer:
int main()
{
bool b = true;
}
We can also use braces {} for initialization:

int main()
{
bool b{ true };
}

These examples declare a (local) variable b of type bool and


initialize it to a value of true. Our variable now holds a value of true.
All local variables should be initialized. Accessing uninitialized
variables results in Undefined Behavior, abbreviated as UB. More on
this in the following chapters.

5.1.2 Character Type


Type char, referred to as character type, is used to represent a single
character. The type can store characters such as 'a', 'Z' etc. The size
of a character type is exactly one byte. Character literals are enclosed in
single quotes '' in C++. To declare and initialize a variable of type
char, we write:

int main()
{
char c = 'a';
}

Now we can print out the value of our char variable:

#include <iostream>

int main()
{
char c = 'a';
Another random document with
no related content on Scribd:
The Project Gutenberg eBook of A new graft on the
family tree
This ebook is for the use of anyone anywhere in the United States and most
other parts of the world at no cost and with almost no restrictions whatsoever.
You may copy it, give it away or re-use it under the terms of the Project
Gutenberg License included with this ebook or online at www.gutenberg.org. If
you are not located in the United States, you will have to check the laws of the
country where you are located before using this eBook.

Title: A new graft on the family tree

Author: Pansy

Release date: September 4, 2023 [eBook #71567]

Language: English

Original publication: London: T. Nelson and Sons, 1902

*** START OF THE PROJECT GUTENBERG EBOOK A NEW GRAFT ON


THE FAMILY TREE ***
Transcriber's note: Unusual and inconsistent spelling is as printed.

"Will you have a card, please?"


A NEW GRAFT
ON THE FAMILY TREE.

BY

PANSY

[ISABELLA ALDEN]

AUTHOR OF "A HEDGE FENCE," "SIDE BY SIDE,"

"STRIVING TO HELP," ETC.


London:

T. NELSON AND SONS, PATERNOSTER ROW.

EDINBURGH; AND NEW YORK.

1902

Contents.

Chapter

I. WILL IT BLOOM, OR WITHER?

II. THE TREE

III. INTRODUCED

IV. FROM DAWN TO DAYLIGHT

V. BEDS AND BUTTON-HOLES

VI. A NEW SERVICE FOR THE SABBATH

VII. A NEW SABBATH CLASS

VIII. NEW LIGHT


IX. A NEW CHAMPION

X. FISHING

XI. GRACE SUFFICIENT

XII. DIFFERENT SHADES

XIII. BUDS OF PROMISE

XIV. DUST AND DOUBT

XV. OPPORTUNITIES

XVI. THE REASON OF THINGS

XVII. FIRST FRUITS

XVIII. BIRDS OF PROMISE

XIX. "WHATSOEVER"

XX. CLOUDS

XXI. HEDGED IN

XXII. CORDS UNSEEN

XXIII. "FORBID THEM NOT"

XXIV. STORM

XXV. UNCONDITIONAL SURRENDER

XXVI. DORRIE'S AMBITION

XXVII. HEART-THROBS AND COMMONPLACES

XXVIII. "I DON'T KNOW"

XXIX. THE OLD AND THE NEW


A NEW GRAFT
ON THE FAMILY TREE.

CHAPTER I.

WILL IT BLOOM, OR WITHER?

"WHAT in the world are you ever going to do with all those tidies?"

The speaker was a girl of sixteen—a fair, bright creature, with dancing eyes,
and that alert expression which we find on the faces of those to whom the
future is an interesting and exciting puzzle which they long to solve.

She was watching with curious interest the absorption of her sister, who knelt
before a half-packed trunk, studying the disposal of packages so as to solve
that old problem, "How to get twice as much into a trunk as it will reasonably
hold."

She made no answer to the young questioner, having just taken up a closely
written sheet of paper, the contents of which absorbed her attention. The
question was repeated.

"Louise, what do you expect to do with all those tidies?"

"Put them on chairs and sofas—" with a far-away expression and dreamy
tone, and eyes only for the paper before her.

The young girl laughed slightly, then her face grew sober.

"Louise," she said, hesitating as one who might be on doubtful ground, "has
Lewis told you anything about his home and its surroundings?"

"Somewhat, dear—" still only half attending to the speaker.

"Well, Addie Dunlop says they live very plainly indeed. She visits the
Wheelers, you know, in that vicinity, and she was at their house on two
different occasions. She says it is quite isolated from neighbours, and is a
regular country farmhouse."

This brought a laugh.

"What would you have a country farmhouse but a country farmhouse?"

"Oh well, Louise, you know what I mean."

If she did she kept the knowledge in silence; and her young sister, after
regarding her with a curious look for a moment, drew a heavy sigh.

"It doesn't seem to me that you belong to country farmhouses," she said
boldly, "with your education and talents. What will you do with them buried
among commonplace—hills?" She had nearly said people, but checked
herself. "Why should Lewis hide himself in that out-of-the-way place?"

"Well, dear, you know it is a question of health with him. Nearly all his plans in
life had to be changed to meet the demands of a failing body. Farm life agrees
with him."

"I don't believe it will with you. I don't like to think of you away off there, miles
away from anything to which you are accustomed. Louise, honestly, aren't you
afraid you will be homesick?"

Thus solemnly questioned, Louise dropped her engrossing paper, and turning
from the trunk, gave the questioner the full benefit of her laughing eyes.

"My dear little grandmother, have you gone and gotten your yourself into a
fever of anxiety over your young and giddy sister? I'm not a bit afraid of a
farmhouse. As for homesickness, of course I shall have that disease. What
sort of a heart would it be that could leave such a home as mine without
longing for it, and the dear faces that belong to it, sometimes many times a
day? But having looked at the matter fairly, it seems to be the right thing to do.
And, my troubled little sister, you want to fully realize this. I am not going
'away off there' alone, but with Lewis Morgan; and if I did not love him enough
to be absolutely certain that I could go to the ends of the earth with him as
well as not, if it should seem best to do so, I assuredly ought not to marry
him."

"And leave papa and mamma!"


It was impossible not to laugh at the startled, tragic tone in which these words
were spoken, as the elder sister repeated them—

"And leave papa and mamma! And also, which is a very important matter,
leave my dear little troubled sister Estelle. Positively, dear, though it has its
sad side, of course, it does not seem too much of a sacrifice for me to make in
order to be with Lewis. If it did, I should think myself unworthy of him."

"How strange!" said the younger sister, though she was wise enough this time
to say it to herself. "I'm sure I don't see how she can do it. Besides papa and
mamma, there is our beautiful home, and all the girls, and the lectures, and
the circles, and—oh, well, everything. According to Addie Dunlop she will just
be buried alive, surrounded by snow in winter and haying and harvesting in
summer. What is there in Lewis Morgan that should make her want to go? I
wouldn't like to go anywhere with him. He is nice enough; he is very nice
indeed, for that matter. I like him as well, if not better, than any of the young
men who call on us. But liking a man and enjoying a half-hour's talk with him,
and going to a lecture or concert with him, is one thing, and going away from
one's father and mother to spend a lifetime with him is another."

The conclusion of her soliloquy was that she said aloud, in tones more
dismayed than before—

"I don't understand it at all! I never could go away with Lewis Morgan, and
leave papa and mamma and everybody."

Whereupon the bride-elect leaned over her open trunk and laughed
immoderately. Her young sister's perplexity seemed so funny to her.

"Of course you couldn't, you dear child," she said, when she could speak.
"You are not expected to want to go away from papa and mamma and live
with Lewis Morgan, though I am sure I hope you will come and live with us half
the time. Farmhouses are very nice places in which to spend summer, Estelle.
But you mustn't wear a woe-begone face over me, and think of me as making
a sacrifice. If you ever give your heart to a good, true man, you will be entirely
willing to go away with him, and until you are you must never think of taking
marriage vows. Meantime, dear, of course you don't understand it; you are
much too young. I hope it will be many a year before the thing will seem
possible to you."

"It will never seem possible," Estelle said stoutly. "If I have got to love any man
enough to be willing to go away from papa and mamma before I can be
married, I shall have to be an old maid; for that is all nonsense. I know no man
on earth could tempt me to do it."

"Very well," said the bride in much composure, "I am glad you think so; it is the
best way to feel. To be sure, people change their minds sometimes; but at
your age it is much the nicest thing to think. Meantime, dear, don't you worry
about those tidies. I shall find places for them, where they will set the nice old-
fashioned rooms aglow with their beauty. I am glad I have so many. Now, do
you suppose that ebony box would fit in this niche? I would like to have it
here, because we shall keep this trunk with us all the time."

"She hasn't the least idea how farmhouses look, especially that one. I wonder
if she has the slightest notion how her future brother-in-law looks? Lewis
Morgan indeed! I wish he had stayed in Australia!" And with another long-
drawn sigh the troubled young sister went in search of the ebony box.

This was not the first time that Louise Barrows, the bride-elect, had been
called upon to vindicate the comforts of her future home. Her father had
demurred and hesitated, and argued the question with his prospective son-in-
law, and the mother had shed some tears in secret over the thought that the
daughter of whom she was so proud had chosen so obscure and prosaic a
future.

"Think of her getting-up at four o'clock in the morning to look after the butter
and milk, and get breakfast for the workmen!" she had said to her husband in
their confidential talks; and he had answered—

"There are worse lots in life than that, I suppose."

But he had sighed as heavily as the young daughter always did when she
thought about it, and he had wished from his inmost heart that things had
shaped differently. Still he essayed to comfort his wife.

"He is Louise's own choice, and he is a good Christian man, with strong, solid
principles. It might have been much worse."

"Oh yes," the mother assented, "he is a Christian man;" and the tone in which
she said it might almost have justified you in expecting her to add: "But that
doesn't amount to much." What she did say was: "But what can Louise do for
herself or others, buried alive out there? She is eminently fitted for usefulness.
You know as well as I that she would grace any circle, and that she is a leader
among her set; she leads in the right direction, too, which is more than can be
said of most girls: but what chance will she have to develop her talents?"
"That is true," the father said, and then he sighed again. Yet these Christian
parents had prayed for their daughter every day since she was born, and
professed assured confidence in the belief that God guides his children and
answers prayer. Still their faith did not reach high enough to get away from a
lurking belief that the Guide of their daughter's life had made a mistake in
setting her future among such surroundings. Not that they put the thought into
such words—that would have been irreverent; but what did their sighings and
regrettings mean?

It was rather hard on the prospective bride, even though her parents were
wise enough to say almost nothing about their regrets, now that the question
was settled. But she felt it in the atmosphere. Besides, she had to encounter a
like anxiety from another source. It was only the evening before Estelle's
cross-questioning occurred that Lewis Morgan himself, getting-up from one of
the luxurious easy-chairs which, repeated in varying patterns, abounded in Mr.
Barrows' parlours, crossed over to the mantel, and, resting his elbow on its
edge and his forehead on his hand, looked down from his fine height on
Louise as she nestled in a brown-tinted plush chair that harmonized perfectly
with her soft, rich dress, and contrasted perfectly with her delicate skin, and
made to the gazer a lovely picture, which seemed but to heighten his
perplexity.

"After all, Louise," he said, "I don't know but we made a mistake in planning as
we did. Someway, out in Australia, where my planning was done, the contrast
between your present home and our future one was not so sharply defined
before me as it is here."

"Shut your eyes, then," said Louise, "and imagine yourself back in Australia,
when you have any planning to do. That is quite as near as I want you to get
to that barbarous country again."

Lewis Morgan laughed, and then immediately his brow clouded.

"But, Louise, there is a fitness in things, and you fit right in here. Everything
matches with you." And his eyes gave a swift journey up and down the room,
taking in its soft and harmonizing furnishings—the richness and glow of the
carpet, the delicacy and grace of the lace curtains, the air of ease and
elegance in the disposal of the elegant furniture, the rare paintings looking
down on him from the walls, glowing in the gas-light, then back to the small,
graceful figure in the brown chair.

"Louise, you are entirely unfamiliar, you know, with country life, and I don't
believe I can give you the least idea of the sharp and trying contrasts."
"Then don't try. Wait, and let me see them for myself."

"Yes, but—what if we wait until it is too late to rectify mistakes? Though, for
that matter, we can change, of course, should the thing prove unbearable. But
I am really afraid it is a mistake. I seem to feel it more to-night than ever
before."

"Lewis," said the little brown figure, "do you really think I am a bird of bright
plumage, that must have a gilded cage and downy nest, and nothing else?"

He looked down on her with unutterable admiration in his eyes.

"Oh, you know very well," he said, half smiling, "that I think you are everything
that any mortal woman can be—possibly a little more. But—well, it is not only
the house and surroundings, though they are rude and plain enough. I am
afraid that you and my mother will not understand each other. She is old-
fashioned and peculiar—she is a good mother, and I love and respect her;
but, Louise, she is not in the least like yours, and I am not sure that she will
have an idea in common with you."

"Yes she will. We shall both bestow an undue amount of admiration on, and
take an absurd degree of comfort in, your tall self."

He laughed again, and then shook his head.

"I doubt whether even there you will not be disappointed. My mother has a
strong, warm love for her family; but she does not show it in the way to which
you have been accustomed. She is reserved, pent-up. She will sit up with my
little sister Nellie six nights in succession; but she never caresses and kisses
her as your mother does Lora."

"Never mind," said Louise; "it is not natural for some people to kiss and
caress. The sitting up is the most important matter after all, especially when
one is sick; though I will own that I am sorry for poor Nellie, without the kisses.
Perhaps we can work together: your mother will do the patient caring for, and I
will do the kissing. How will that work?"

"I see you are bent on making everything shine with the brightness of your
own spirit. But, really and truly, I am afraid I have been dreaming a wild dream
in supposing that I could transplant you to such a rough atmosphere. It was
ridiculous in my father to put in the proviso that we must live at home. I ought
to have resisted it. Because I must spend my days out of doors, travelling over
a farm, is no reason why we shouldn't have a home of our own. I think my
father is abundantly able to give me a separate start, if he only saw the matter
in that light."

"But since he doesn't, we must, like dutiful children, try to see it in his light,
until such time as we can win him over to our notions or become full converts
to his. I know all about it, Lewis. I don't expect to walk in a garden of roses all
the time. I know, too, that to go into farm life is a trial to you. All your plans
were in another channel. Yet I am more than glad to give up all those rose-
coloured plans for the sake of seeing you look at this moment as strong and
well es your summer on a farm has made you. I fully intend to be happy on
that farm. I shall have to make a confession to you. Papa talked seriously to
me about trying to rent a farm and stock it for us, and do you know I
controverted it?"

"I should think so," said Lewis Morgan hastily. "He ought not to spare the
money from his business. And, besides, it would be unjust as he is situated."

"Well, I didn't enter into that part of it. I simply said that I thought duty to your
father obliged you to yield to his very decided wishes in this matter, and that
you and I were both resolved on a thorough trial of it. And, really, I don't
apprehend any dreadful consequences. I want to try the experiment of living
with my mother-in-law and having a thoroughly good time in doing it. And,
Lewis, there is one subject on which we surely can agree. You forget the most
important one of all."

He shook his head, and his voice was low and sad.

"No, I don't, Louise. You are mistaken: not one of the family, save myself, is a
Christian."

The first shadow that he had seen on his bride's face, when this subject was
being discussed, flitted across it now. At last he had startled her.

CHAPTER II.
THE TREE.
"APPEALING to your Father in heaven to witness your sincerity, you, Lewis,
do now take this woman whose hand you hold, choosing her alone from all
the world, to be your lawfully wedded wife? You trust her as your best earthly
friend; you promise to love, cherish, and protect her; to be considerate of her
happiness in your plans of life; to cultivate for her sake all manly virtues, and
in all things to seek her welfare as you seek your own? You pledge yourself
thus honourably to be her husband in good faith, so long as God in his
providence shall spare you to each other?"

"In like manner, looking to your heavenly Father for his blessing, you, Louise,
do now receive this man, whose hand you hold, to be your lawfully wedded
husband? You choose him from all the world, as he has chosen you; you
pledge your trust to him as your best earthly friend; you promise to love, to
comfort, and to honour him; to cultivate for his sake all womanly graces; to
guard his reputation and to assist him in his life-work, and in all things to
esteem his happiness as your own? You give yourself thus trustfully to him to
be his wife in good faith so long as the providence of God shall spare you to
each other?"

The old story, repeated so many hundred times since the world was new, and
yet so new a story to each one who becomes an actor in it that it quickens the
pulses and pales the cheek.

Estelle Barrows, alert, eager, keen-eared, listened with flushing cheeks and
quickened breathing to the interchange of solemn vows, and shivered over the
closeness of the promises, and marvelled at the clear steadiness of her
sister's voice as she answered, "I do." The same sceptical spirit was in Estelle
that had governed her during her talk with her sister. She could not yet see
how such things were possible. It was all very well for Lewis to promise to
trust Louise as his "best earthly friend,"—of course she was; to promise to
love, cherish, and protect her—it was the least he could do after she had
given up so much for him. "To be considerate for her in his plans for life."
Estelle almost thought that he ought to have hesitated over that promise. Had
he been considerate? Did he think that home in the far-away farmhouse would
be conducive to her happiness? Still he doubtless meant his best, and it was
right enough for him to ring out his "I do" in a strong manly voice. But for
Louise, how could she say he was her best earthly friend, with papa looking
down on her from his manly height and mamma struggling to hold back the
tears? How could she promise to assist him in his life-work? Suppose his
entire life had to be spent on that hateful farm, must Louise bury herself there
and assist him? How would she do it? Would he expect her, sometimes, to
even milk the cows! She had heard that farmers' wives did these things. Or
could she be expected to churn the butter, or work it, or mould it ready for
market, and then to drive into town on a market-waggon and barter her rolls of
butter for woollen yarn to knit him some socks? She had stood with a sort of
terrified fascination at one of the busy corners of the city only the day before,
and watched a market-woman clamber down from her height and take a pail
of butter on one arm and a basket of eggs on the other, and tramp into the
store. She had told it to Louise afterward, and she had laughed merrily over
the discomforted face, and had asked if the woman did not look rosy-cheeked
and happy.

All these and a hundred other commingling and disturbing thoughts floated
through Estelle's brain as she watched the quiet face of her sister during the
ordeal of marriage. Even after the hopelessly binding words, "I pronounce you
husband and wife," had been spoken, she still stood, gazing and wondering.
She could never, never do it. Marriage was nice enough in the abstract, and
she liked to go to weddings, at least she had always liked to before this one.
But to single out one man and make him the centre of all these solemn and
unalterable vows! And that man to be Lewis Morgan!

Louise seemed entirely unconscious of the necessity for any such turmoil of
brain on her account. She looked as serenely sweet and satisfied in her white
silk robes as she had in the simple gold-brown that had been one of her
favourite home dresses. Oh yes; she was in white silk and bridal veil and
orange blossoms, and the blinds were closed, and the heavy curtains dropped
(although it was mid-day), and the blaze of the gas lighted up the scene; and
there was a retinue of bridesmaids, in their white robes and their ten-buttoned
kids, and there were all the et ceteras of the modern fashionable wedding!

All these things fitted as naturally into the everyday life of the Barrows family
as hard work and scanty fare fit into the lives of so many. They had not
discussed the question at all, but had merely accepted all these minor details
as among the inevitables, and made them ready. Mrs. Barrows came from an
aristocratic and wealthy family; so also did the father; and all the surroundings
and associations of the family had been connected with wealth and
worldliness to such a degree that, although they were reckoned among their
set as remarkably plain and conscientiously economical people, viewed from
Lewis Morgan's standpoint they were lavish of their expenditures to a degree
that he knew his father would have denounced as unpardonable.

Is not it a pity that in this carping world we cannot oftener put ourselves in
other people's places, mentally at least, and try to discover how we should
probably feel and talk and act were we surrounded by their circumstances and
biased by their educations? Something of this Lewis Morgan had done. He
might almost be said to occupy half-way ground between the rigid plainness of
his country home life and the luxurious ease of his wife's city home life. He
had been out into the world, and had seen both sides, and his nature was
broad enough and deep enough to distinguish between people and their
surroundings. Therefore, while he admired and respected Mr. Barrows, he
respected and loved his father, who was the very antipodes of his city brother.

Hundreds of miles away from the gas-lights and glamour of orange blossoms,
and bridal veils, and wedding favours, on a bleak hillside, was a plain two-
story frame house, surrounded by ample barns, which showed in their
architecture and design a more comfortable finish for the purposes for which
they were intended than the plain unpainted house had ever shown. There
was even a sense of beauty, or at least of careful neatness, in the choosing of
the paints and the general air of the buildings, that the house lacked.
Whatever Jacob Morgan thought of his family, it was quite apparent that he
had a high opinion of his stock.

Within this square, plain, solemn-looking house, on a certain dull and solemn
autumn evening, sat the Morgan family, gathered apparently for a special
occasion; for though every one of them, down to the gray old cat purring
behind the great wood stove, tried to act as usual, a general air of expectancy,
indescribable and yet distinctly felt, pervaded the room.

The room, by the way, deserves a passing description. It was at once the
sitting-room, dining-room, and kitchen of the Morgans. It was large and
square, and scrupulously clean. There was a large old-fashioned table, with
its great leaves turned down, and itself pushed up against the north side of the
house; and it had a dark, flowered, shiny oil-cloth spread all over its surface,
reaching down nearly to the floor. On the oiled surface a large-sized, old-
fashioned candlestick held a substantial tallow candle, which served to show
Mother Morgan where to put the point of the great darning-needle as she
solemnly wove it in and out of the gray sock drawn on her large, labour-
roughened hand. The old-fashioned tray and snuffers stood beside the
candlestick, and a dreary-faced girl, in a dark calico dress, closely buttoned at
the throat and guiltless of a collar, occupied herself in applying the snuffers at
regular intervals to the black wick that rapidly formed.

Occasionally the mother hinted that it was a very shiftless way to spend her
time, and that she would do better to get out her mending or her knitting. But
the girl, with a restless sort of half-sigh, replied that she "couldn't mend or knit
to-night."

You might also like