100% found this document useful (1 vote)
4 views

Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards 1st Edition Slobodan Dmitrović instant download

The document is a promotional description for the book 'Modern C++ for Absolute Beginners' by Slobodan Dmitrović, which serves as an introduction to C++ programming and covers standards from C++11 to C++20. It includes links for downloading the book and mentions additional resources available on GitHub. The document also outlines the table of contents, detailing various chapters that cover fundamental concepts and advanced features of C++.

Uploaded by

pearsezzat9j
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
4 views

Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards 1st Edition Slobodan Dmitrović instant download

The document is a promotional description for the book 'Modern C++ for Absolute Beginners' by Slobodan Dmitrović, which serves as an introduction to C++ programming and covers standards from C++11 to C++20. It includes links for downloading the book and mentions additional resources available on GitHub. The document also outlines the table of contents, detailing various chapters that cover fundamental concepts and advanced features of C++.

Uploaded by

pearsezzat9j
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Modern C++ for Absolute Beginners: A Friendly

Introduction to C++ Programming Language and


C++11 to C++20 Standards 1st Edition Slobodan
Dmitrovi■ download
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/

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

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 [email protected], 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 Scribd Document
with Unrelated Content
The Project Gutenberg eBook of A Sermon,
Delivered Before His Excellency Edward
Everett, Governor, His Honor George Hull,
Lieutenant Governor, the Honorable Council,
and the Legislature of Massachusetts, on the
Anniversary Election, January 2, 1839
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 Sermon, Delivered Before His Excellency Edward Everett,


Governor, His Honor George Hull, Lieutenant Governor, the
Honorable Council, and the Legislature of Massachusetts,
on the Anniversary Election, January 2, 1839

Author: Mark Hopkins

Release date: August 6, 2012 [eBook #40428]


Most recently updated: October 23, 2024

Language: English

Credits: Produced by Bill Tozier, Julia Neufeld and the Online


Distributed Proofreading Team at http://www.pgdp.net

*** START OF THE PROJECT GUTENBERG EBOOK A SERMON,


DELIVERED BEFORE HIS EXCELLENCY EDWARD EVERETT,
GOVERNOR, HIS HONOR GEORGE HULL, LIEUTENANT GOVERNOR,
THE HONORABLE COUNCIL, AND THE LEGISLATURE OF
MASSACHUSETTS, ON THE ANNIVERSARY ELECTION, JANUARY 2,
1839 ***
A

SERMON
DELIVERED BEFORE
HIS EXCELLENCY EDWARD EVERETT,
GOVERNOR,
HIS HONOR GEORGE HULL,
LIEUTENANT GOVERNOR,
THE HONORABLE COUNCIL,
AND
THE LEGISLATURE OF MASSACHUSETTS,
ON THE
ANNIVERSARY ELECTION,
JANUARY 2, 1839.
BY MARK HOPKINS, D. D.
President of Williams College.

Boston:
DUTTON AND WENTWORTH, PRINTERS TO THE STATE.
1839.

Commonwealth of Massachusetts.

SENATE, JANUARY 3, 1839.

Ordered, That Messrs. Filley, Quincy, and Kimball, be a Committee to


present the thanks of the Senate to the Rev. Mark Hopkins, D. D. for
the discourse yesterday delivered by him, before the Government of
the Commonwealth, and to request a copy thereof for publication.
Attest,
CHARLES CALHOUN, Clerk.
SERMON.
Acts v. 29.

WE OUGHT TO OBEY GOD RATHER THAN MAN.

Man was made for something higher and better, than either to make,
or to obey, merely human laws. He is the creature of God, is subject
to his laws, and can find his perfection, and consequent happiness,
only in obeying those laws. As his moral perfection, the life of his
life, is involved in this obedience, it is impossible that any power
should lay him under obligation to disobey. The known will of God, if
not the foundation of right, is its paramount rule, and it is because
human governments are ordained by him, that we owe them
obedience. We are bound to them, not by compact, but only as
God's institutions for the good of the race. This is what the Bible,
though sometimes referred to as supporting arbitrary power, really
teaches. It does not support arbitrary power. Rightly understood, it is
a perfect rule of duty, and as in every thing else, so in the relations
of subjects and rulers. It lays down the true principles, it gives us
the guiding light. When the general question is whether human
governments are to be obeyed, the answer is, "He that resisteth the
power, resisteth the ordinance of God." "The powers that be are
ordained of God." But when these powers overstep their appointed
limits, and would lord it over the conscience, and come between
man and his maker, then do we hear it uttered in the very face of
power, and by the voice of inspiration, no less than of indignant
humanity, "We ought to obey God rather than men."
It has been in connexion with the maintenance of this principle, first
proclaimed by an Apostle of Christ eighteen hundred years ago, that
all the civil liberty now in the world has sprung up. It is to the
fearless assertion of this principle by our forefathers, that we owe it
that the representatives of a free people are assembled here this day
to worship God according to the dictates of their own consciences,
to seek to Him for wisdom in their deliberations, and to acknowledge
the subordination of all human governments to that which is divine.
Permit me then, as appropriate to the present occasion, to call the
attention of this audience,
1st. To the grounds on which all men are bound to adhere to the
principle stated in the text; and
2d. To the consequences of such adherence, on the part, both of
subjects, and of rulers.

I observe, then, that we ought to obey God rather than men,


because human governments are comparatively so limited and
negative in their bearing upon the great purposes, first, of individual,
and second, of social existence.
The purposes for which man was made, must evidently involve in
their accomplishment, both his duty and his happiness; and nothing
can be his duty which would contravene those purposes. Among
them, as already intimated, the highest is the moral perfection of the
individual; for as it is by his moral nature that man is distinguished
from the inferior animals, so it is only in the perfection of that
nature, that his perfection, as man, can consist. As absolute
perfection can belong only to God, that of man must be relative, that
is, it must consist in the proper adjustment of relations, and
especially in the relation of his voluntary actions to the end for which
God designed him. This is our idea of perfection, when we affirm it
of the works of man. It involves, mainly, such a relation of parts as is
necessary to the perfect accomplishment of the end in view. A watch
is perfect when it is so constructed that its motions exactly
correspond in their little revolutions with those of the sun in the
heavens; and man is perfect when his will corresponds in its little
circle of movement with the will of God in heaven. This
correspondence, however, is not to be produced by the laws of an
unconscious mechanism, but by a voluntary, a cheerful, a filial co-
operation. It is this power of controlling his faculties with reference
to an ultimate end, of accepting or rejecting the purpose of his
being, as indicated by God in the very structure of his powers, and
proclaimed in his word, that contradistinguishes man from every
inferior being, and gives scope for what is properly termed,
character. Inferior beings have qualities by which they are
distinguished, they have characteristics, but not character, which
always involves a moral element. A brute does not govern its own
instincts, it is governed by them. A tree is the product of an agency
which is put forth through it, but of which it is not conscious, and
which it does not control. But God gives man to himself, and then
sets before him, in the tendency of every thing that has unconscious
life towards its own perfection, the great moral lesson that nature
was intended to teach. He then causes every blade of grass, and
every tree, to become a preacher and a model, calling upon him to
put forth his faculties, not without law, but to accept the law of his
being, and to work out a character and a happiness in conformity
with that. It is, as I have said, the power which man has to accept
or reject this law of his being, the great law of love, that renders him
capable of character, and it is evidently as a theatre, on which this
may be manifested, that the present scene of things is sustained.
Not with more certainty do the processes of vegetation point to the
blossoms and the fruit as the results to which they conspire, than
does every thing in the nature and condition of man indicate the
formation of a specific, voluntary, moral character, as the purpose for
which God placed him here. But this purpose is not recognized at all
by human governments, and we have only to observe the limited
and negative agency which they incidentally bring to bear upon it, to
see how insignificant must be their claims when they would come
into conflict with those of the government of God.
I observe then, first, that human governments regard man solely as
the member of a community; whereas it is chiefly as an individual,
that the government of God regards him. Isolate a man from society,
take him beyond the reach of human government, and his faculties
are not changed. He is still the creature of God, a dweller in his
universe, retaining every thing he ever possessed that was noble in
reason, or grand in destiny, and in his solitude, where yet he would
not be alone, the government of God would follow him, and would
require of him such manifestations of goodness as he might there
exercise—the adoration of his Creator, resignation to his will, and a
temperate and prudent use of the blessings within his power.
Indeed, so far as responsibility is concerned, the divine government
considers man, whether in solitude or in a crowd, solely as an
individual, and produces an isolation of each as complete as if he
were the only person in the universe. God knows nothing of divided
responsibility, and whether acting alone, or as a member of a
corporation or of a legislature, every man is responsible to him for
just what he does as a moral being, and for nothing more. The
responsibility of each is kept disentangled from that of all others,
and lies as well defined in the eye of God, as if that eye were fixed
upon him alone. The kingdom of God is within man, and there it is,
in the secret soul of each, that the contest between light and
darkness, between God and Satan is going on, and in the struggle,
in the victory or the defeat, he who walks the city is as much alone
as the hermit in his cell. It is over the thoughts of man, his
affections, his passions, his purposes, which mock at human control,
that the government of God claims dominion; it is with reference to
these, and not to the artificial index of appearances which we set to
catch the eye of the world, that the register of Heaven is kept. On
the other hand, how very few of the moral actions of man can
human government reach, how imperfectly can it reach even these!
It is only of overt acts, those which it can define, and which can be
proved before a human tribunal, that it can take cognizance; and its
treatment even of these can never be adjusted to the varying
shades of guilt. It has no eye to reach the springs of action. It may
see the movements of the machinery above, perplexed, and
apparently contradictory; but it cannot uncover the great wheel, and
look in upon the simple principle which makes character, and sets
the whole in motion.
But I observe again, that human governments are not only thus
limited, but are also chiefly negative in their influence upon the
formation of individual character. There is, indeed, a positive and
widely pervading moral influence connected with the character, and
station, and acts, of those who are in authority. This cannot be too
prominently stated, the responsibility connected with it cannot be
too carefully regarded; still this influence is entirely incidental, and is
the same in kind with that exerted by any distinguished private
individual. Human governments have also positive power to furnish
facilities, as distinguished from inducements. They can authorise and
guard the issue of paper money, to give facilities to men of business;
they can lay down rail-roads, thus opening facilities to the spirit of
enterprise, and calling out the neglected resources of the State; they
can too, and our fathers did it, construct and keep in repair the rail-
roads of the mind, thus giving facilities to the poorest boy in the
glens of the mountains to come out and be an honor to his country.
Still, human government is chiefly a system of restraint for the
purpose of protection. Its object is to give equal protection to all in
using their faculties as they please, provided they do not interfere
with the rights of others. It does not propose to furnish
inducements, but to enable men to live quiet and peaceable lives,
while they act in view of the great inducements furnished by the
government of God.
In saying this, I do not undervalue the benefits conferred by human
governments, but only assign them their true place. The office
performed by them is indispensable. They are the enclosure of the
field, without which certainly nothing could come to maturity; but
they are not the soil and the rain, and the sunshine, which cause
vegetation to spring up. These are furnished by the government of
God, which is not only a system of restraint and protection, but also,
and chiefly, of inducements to excellence. Into the ear of the
humblest of its subjects it whispers, as it points upward, "Glory,"
"Honor," "Immortality," "Eternal Life." It is parental in its character,
makes us members of a family, gives us objects of affection, and by
its perfect standard of moral excellence, and the character of God
which it sets before us, it purifies and elevates the mind. Without a
God to whom he is related and accountable, man has neither dignity
nor hope. Without God, the universe has no cause, its contrivances
indicate no intelligence, its providence no goodness, its related parts
and processes no unity, its events no convergence to one grand
result, and the glorious spectacle presented in the earth and the
heavens, instead of calling forth admiration and songs, is an enigma
perplexing to the intellect, and torturing to the heart. Seen in its
connexion with God, the universe of matter is as the evening cloud
that lies in the sunlight, radiant, and skirted with glory; without him
it is the same cloud cold and dark when that sunlight is gone.
Without God, man is an orphan; he has no protector here, and no
Father's house in which he may hope for a mansion hereafter. His
life is at his own disposal, and has no value except in relation to his
personal and present enjoyment.
On the other hand, as the idea of God is received, and his relations
to the universe are intimately felt, unity and harmony are introduced
into our conceptions of that which is without, and acquiescence and
hope reign within. Nature, as more significant, becomes more a
companion. Her quiet teachings and mute prophecies, her indexes
pointing to the spirit land, instead of being felt as a mockery, are in
accordance with the best hopes, and the revealed destiny of man.
Life, too, assumes a new aspect. A common destiny is set before all,
and the consciousness of it runs as a thread of sympathy through
the race. The poor man is elevated when he sees that the principle
of duty may be tried and strengthened in his humble sphere, as well
as in those that are higher, and his labor becomes a cheerful service
done with good will from the heart. Every duty to man becomes
doubly sacred as due also to God, and the humblest life, pursued
from a conscientious regard to his will, is invested with an
unspeakable dignity. It is indeed, I may remark, this view of life that
furnishes the only possible ground of equality. Men are upon an
equality only as they are equally upon trial in the sight of God, and
nothing will ever reconcile them to the unavoidable inequalities of
the present state, but the consciousness that their circumstances
were allotted to them by Him who best knew what trials they would
need, and whose equal eye regards solely the degree in which their
moral nature is improved by the trial. When this is felt, there is,
under all circumstances, a basis for dignity without pride, for activity
without restlessness, for diversity of condition without discord.
And not only the aspect of life in the relations of men to each other,
but its end also is changed. The moral nature assumes its true
position, and, acting in the presence of a perfect law as its standard,
and of a perfect gospel as its ground of hope, the idea of true liberty
dawns upon the mind. This consists in the coincidence of the
affections and inclinations with correct principle. It is only when the
internal constitution of a reasonable being is in harmony with the
law under which he acts, that he is conscious of no restraint, and
knows what true freedom is. The chief value of what is commonly
called liberty, consists in the opportunity it gives to use our faculties
without molestation for the attainment of this. This is that glorious
liberty of the sons of God, of which the Scriptures speak. It is not a
mere freedom from restraint which may be abused for the purposes
of wrong-doing; and become a curse, merely making the difference
between a brute enclosed and a brute at large; but it is, in its
commencement, the resolute adoption of the law of conscience and
of God as the rule of life; in its progress, a successful struggle with
whatever opposes this law; in its completion, the harmonious and
joyful action of every power in its fulfilment. This is the only liberty
known under the government of God. He who knows it not is the
slave of sin. He who struggles not for it, is in a contented bondage
of which physical slavery is but a feeble type. The perfection of this
liberty is only another name for moral perfection, which, as I have
said, is the great end of the individual; and as the direct motives and
means for the attainment of this are furnished only by the
government of God, it is evident that "We ought to obey God rather
than men."
Having thus spoken of the effect of human government upon man in
his individual character, I now proceed to inquire, whether it is
equally limited and negative in its bearing upon him in his social
condition.
And here I remark, that it is only incidentally that human
government is necessary to man as a social being at all. Society was
before government, and if man had retained his original state, it
might, perhaps, have existed without it till the end of time. Man is
constituted by his Creator a social being; he has faculties to the
expansion and perfection of which society is requisite, but he has no
faculties the necessities of which constitute him a political being.
There must be politicians, just as there must be farmers, and
merchants, and physicians, that they and others may enjoy social
life; but social life is corrupted when politics enter largely into it. It is
not sufficiently noticed, that it is through social institutions and
habits far more than through political forms, that the happiness or
misery of man is produced. It was not from the oppressions of the
government, but from a corrupted social state, that the prophet of
old wished to flee into the wilderness. It was because his people
were all adulterers, an assembly of treacherous men, because every
brother would supplant, and every neighbor would walk with
slanders. Such a state of things may exist under any form of political
organization. It may exist under ours. Men may be loud in their
praise of republican forms, and yet be false, and unkind, and
litigious; they may be indolent, and profane, and sabbath breakers,
and gamblers, and licentious, and intemperate. Yes, and there may
be neighborhoods of such men, and the place where they assemble
nightly, hard by a banner that creaks in the wind, may be the
liveliest image of hell that this earth can present. I certainly know,
and my hearers are fortunate if they do not know, neighborhoods in
this land of liberty and equality, where the only use made of liberty
is to render families and society wretched, and where the only
equality, is an equality in vice and social degradation, which no man
is permitted even to attempt to rise above without constant
annoyance. Better, far better, is family affection, and kind
neighborhood under a regal, or even a despotic government, than
such liberty as this.
Government then is not an end, but a means. Society is the end,
and government should be the agent of society, to benefit man in his
social condition. The extent to which it can do this will depend on its
form, and the power with which it is entrusted. Absolute power,
which should be used for this purpose, is generally abused.
Considering itself as having interests distinct from those of the
people, it too often seeks to keep them in a state of degradation,
and to appropriate to itself the largest possible share of those
blessings which ought to be equally diffused. "Get out of my
sunlight," said Diogenes to Alexander the Great: "Get out of my
sunlight"—cease to obstruct the free circulation of blessings intended
for all, might the people say under any arbitrary form of government
ever yet administered. Still, such a government, when under the
direction of wisdom and benevolence, has power to produce great
social and moral revolutions for the good of mankind. Such a
revolution was commenced by Peter the Great, and his measures,
though necessary, were such as none but an absolute monarch
could have adopted. Aside from christianity, the judicious exercise of
such a power is the only hope of a people debased beyond a certain
point. The King of Prussia can maintain a better and more efficient
system of schools, than any republican government. He can provide
qualified teachers, and can compel the children to attend.
But when, as in this country, government is the direct agent of
society, when it is so far controlled by the people as to secure the
majority at least from oppression, being merely an expression of the
will of that majority, it can have no power to produce moral and
social reformations. Laws do not execute themselves, and in such a
state of things they cannot be effectually executed if the violation of
them is upheld by public sentiment. In such a case, when vices
begin to creep in, and the tendency of things is downwards, we
must have a force different from that of the government; we must
have moral power. Here religion comes in, and must come in, or "the
beginning of the end" has come. The intellect must be enlightened,
and the conscience quickened, and moral life infused into the mass;
the good and the evil must commingle in free conflict, and public
sentiment must be changed. When this is done, when patriotism,
and philanthropy, and religion, have caused an ebb-tide in the flood
of evil that was coming up over the land, then government may
come in, not to carry forward a moral reformation by force, but to
erect a barrier against the return of that tide. It can secure what
these agents have gained. It can put a shield into the hands of
society, with which it can, if it pleases, protect itself against that
selfishness and malignity which always lurk in its borders, and which
moral influence cannot reach. If, for example, polygamy were
established among us as it is among the Turks, a government like
ours could do nothing for its removal. But religion could awaken a
sense of obligation, and statistics could point out the number of poor
women and uneducated children thrown by it for support mainly
upon those who had pledged themselves to be the husband of one
wife, and christian and philanthropic effort might show that it was
injurious to individuals, and families, and the state; and then a law
might be passed, as there has been, to defend society against this
evil.
This inefficacy of our government to produce moral and social
reformations should be well understood, because it throws the
fearful responsibility of maintaining our institutions directly upon the
people, where it must rest. A government originating in society, can
have but slight ground to stand on in resisting its downward
tendency. That there is in society such a tendency, all history shows.
As nations have become older, they have invariably become more
corrupt. They have never reached that point in general morality at
which men cease to corrupt each other by associating together. Such
a tendency, not counteracted, must be fatal to republican
governments, for republican government is self-government, and as
the internal law becomes feeble, external force must be increased;
and accordingly we find that every people hitherto, have either been
under regal power from the beginning, or have, in time, reached a
point in corruption, when that power became necessary. Republican
government then, is not so much the cause of a good social state, as
its sign. It can never be borne up, with its stars and stripes floating,
upon the surface of a society that is not strongly impregnated with
virtue. Take this away, and it goes down by its own weight, and the
beast of tyranny, with its seven heads and ten horns, comes up out
of the troubled waters. Here is the turning point with us. All depends
upon the influences that go to form the character of our people.
Those who control these influences will really govern the country. To
this point we turn our eyes anxiously. At this point we look to
legislators to stand in their lot, and do what is appropriate to their
station. At this point we look especially to fathers and mothers, the
guardians of domestic virtue.—Those waters will be sweet that are
fed by sweet springs. We look to christian ministers, to enlightened
teachers, to patriotic authors and editors, to every good citizen. If
there ever was a country in which all these were called upon to do
their utmost, this is that country; if there ever was a government
that was called upon to second in every proper way the efforts of
these, this is that government. To all these we look; but our trust is
only in the influences they may bring to bear from the blessed
gospel of Christ, from the government of God. "We ought to obey
God rather than men."

I have thus shown, as fully as the time would permit, though far too
briefly to do justice to the subject, the grounds on which we ought
to obey God rather than men. These are to be found in the relation
of the divine, and of human government respectively, to the ends of
individual, and of social existence. But the occasion on which the
text was uttered, a subject having directly refused obedience to
rulers lawfully constituted, will lead us to consider the effects of the
principle of the text when acted upon by men in those relations in
which civil liberty is directly involved—in the relations of subjects and
of rulers. What then will be the effect of an adherence to this
principle on the part of subjects, as such?
There is a tendency in irresponsible power to accumulate. It first
gains control over property, and life, and every thing from which a
motive to resistance based on the interests of the present life, could
be drawn. But it is not satisfied with this. Nothing avails it so long as
there is a Mordecai sitting at the King's gate that does not rise up
and do it reverence. It must also control the conscience, and make
the religious nature subservient to its purposes. Accordingly, the
grand device of the enemies of civil liberty, has been so to
incorporate religion with the government, that all those deep and
ineradicable feelings which are associated with the one, should also
be associated with the other, and that he who opposed the
government should not only bring upon himself the arm of the civil
power, but also the fury of religious zeal. The most melancholy and
heart-sickening chapter in the history of man, is that in which are
recorded the enormities committed by a lust of power, and by
malignity, in alliance with a perverted religious sentiment. The light
that was in men has become darkness, and that darkness has been
great. The very instrument appointed by God for the deliverance and
elevation of man, has been made to assist in his thraldom and
degradation. When christianity appeared, the alliance of religion with
oppressive power was universal. In such a state of things, there
seemed no hope for civil liberty but in bringing the conscience out
from this unholy alliance, and putting it in a position in which it must
show its energies in opposition to power. This christianity did. It
brought the conscience to a point where it not only might resist
human governments, but where, as they were then exercised, it was
compelled to resist them. This appeared when the text was uttered,
and there was then a rock raised in the ocean of tyranny which has
not been overflowed to this day. The same qualities which make the
conscience so potent an ally of power, must, when it is enlightened
by a true knowledge of God and of duty, and when immortality is
clearly set before the mind, make it the most formidable of all
barriers to tyranny and oppression.
By thus bringing the moral nature of man to act in opposition to
power, and by giving him light, and strength, and foothold, to enable
him to sustain that opposition, christianity has done an inestimable
service, and has placed humanity at the only point where its highest
grandeur appears. At this point, sustained by principle, and often in
the person of the humblest individual, it bids defiance to all the
malice of men to wrest from it its true liberty. It bids tyranny do its
worst, and though its ashes may be scattered to the winds, it leaves
its startling testimony, and the inspiration of its great example to
coming times. The power to do this, christianity alone can give. No
other religion has ever so demonstrated its evidences to the senses,
and caused its adaptations to the innermost wants of the soul to be
felt, as to enable man to stand alone against the influence of
whatever was dear in affection, and flattering in promises, and
fearful in torture. Other religions have had their victims, who have
been led, amidst the plaudits of surrounding multitudes, to throw
themselves under the wheels of a system already established; but
not their martyrs, who, when duty has permitted it, have fled to the
fastnesses of the mountains; and when it has not, have stood upon
their rights, and contested every inch of ground, and met death
soberly and firmly, only when it was necessary. When this has been
done by multitudes it has caused power to respect the individual, to
respect humanity; and while christianity was wading through the
blood of ten persecutions, it was fighting more effectually than had
ever been done before, the battles of civil liberty. The call to obey
God rather than men met with a response, and it is upon this ground
that the battle has been opened in every case in which civil liberty
now exists. It is upon this ground alone that it can be maintained.
I deem it of great importance that this point should be fully and
often presented, because it is vital, and because there are constant
attempts made to obscure it. Whatever elevates the individual,
whatever gives him worth in his own estimation and that of others,
whatever invests him with moral dignity, must be favorable both to
pure morality and to civil liberty. Hence it is that these are both
incidental results of christianity. They are not the gifts which she
came to bestow—these are life and immortality. They are not the
white raiment in which her followers are to walk in the upper
temple; but they are the earthly garments with which she would
clothe the nations—they are the brightness which she leaves in her
train as she moves on towards heaven, and calls on men to follow
her there. These belong to her alone. Infidels may filch her morality,
as they have often done, and then boast of their discoveries. But in
their hands that morality is lopped off from the body of faith on
which it grew, and produces no fruit. They may boast, as they do, of
a liberty which they never could have achieved. But under its
protection they advance doctrines and advocate practices which
would corrupt it into license. Their only strength lies in endeavoring,
in the sacred name of liberty, to corrupt the virtuous, and to excite
the hatred of the vicious against those restraints without which
liberty cannot exist, and society has no ground of security.
"Promising liberty to others, they are themselves the servants of
corruption." Liberty cannot exist without morality, nor general
morality without a pure religion.
The doctrine thus stated is fully confirmed by history. The
reformation by Luther was made on strictly religious grounds. He
found an opposition between the decrees of the Pope and the
commands of God, and it was the simple purpose, resolutely
adhered to, to obey God rather than men, that caused Europe to
rock to its centre. In the train of this religious reformation civil liberty
followed, but became settled and valuable only as religious liberty
was perfected. It was every where on the ground of conscience
towards God that the first stand was taken, and in those countries
where the struggle for religious liberty commenced but did not
succeed, as in Spain and Italy, civil liberty has found no resting place
for the sole of her foot to this day. It is conceded even by Hume that
England owes her civil liberty to the Puritans, and the history of the
settlement and progress of this country as a splendid exemplification
of the principle in question, needs but to be mentioned here.
In speaking thus of the resistance of christian subjects to the
government, perhaps I should guard against being misunderstood.
In no case can it be a factious resistance. It cannot be stimulated by
any of the ordinary motives to such resistance—by discontent, or
passion, or ambition, or a love of gain. In no case can it show itself
in the disorganizing, the aggressive, and in a free government, the
suicidal spirit of mobs. Christians have in their eye a grand and a
holy object, and all they wish is to go forward, without violating the
rights of others, to its attainment. In so doing they set themselves in
opposition to nobody, but merely exercise an inalienable right, and if
others oppose them, they must still go forward and obey God, be
the consequences what they may.

We will now consider, as was proposed, the effect of an adherence


to the principle of the text on the part of rulers. This becomes
appropriate from the peculiar form of our government, and the
relation which the rulers hold to the people. Rulers have indeed, in
all countries, need to be exhorted to obey God, but when their will is
supreme, and their power is independent of the people, there can be
no propriety in exhorting them to obey God rather than men. In this
country, however, this principle needs to be enforced upon
legislators and rulers quite as much as upon the people, perhaps
even more. It is at this point, if I mistake not, that we are to look for
the danger peculiar to our institutions through those in authority. In
other countries the danger is from the accumulation and tyrannical
use of power. With us, limited as is the tenure of office, there is little
danger of direct oppression. The danger is that those who are in
office, and those who wish for it, will, for the sake of immediate
popularity, lend the sanction of their names to doctrines and
practices, which, if carried into effect, must destroy all government.
How is it else that mobs should often escape with so little rebuke?
How is it else that we hear such extravagant and disorganizing
doctrines maintained in regard to the rights of a majority respecting
property, and their power to set aside any guaranties of former
Legislatures? Certainly the people are the fountain of power. They
establish the government, they have a right to alter it; but when it is
established, the state becomes personified through it, and its acts
are to be consistent. When it is established, it is a government, it
has authority, it becomes God's institution, and those who administer
it are to obey God rather than men. Wo to this country, when the
people shall become to those in place, the object of adulation and of
an affected idolatry. Wo to this country, when the people shall cease
to reverence the government as the institution of God because it is
established through them; when they shall suppose that it is in such
a sense theirs, that they can supersede its acts in any way except by
constitutional forms.
There is also another reason why the principle of the text ought to
be especially regarded by the rulers of this country. So far as a
nation can be considered and treated as a moral person, its
character must be indicated by the acts of its rulers. Accordingly, we
find that under every form of government, God has made nations
responsible, as in the natural course of things they evidently must
be, for what is done by their rulers. But if this is so in monarchical
governments, where the agency of the people is so little connected
with public acts, much more must it be so in one like ours. Here the
rulers represent the people more immediately. They indicate in the
eyes of the world, the moral condition of the people, and hence the
peculiar responsibility of those who act under the oath of God in
making and administering the laws of a representative government.
If it can ever be required of God to vindicate his administration by
the treatment of any people, it must be of one whose government is
thus administered.
I observe then that the principle of the text should be adopted by
rulers, because it furnishes the only broad and safe basis of political
action. The adoption of this principle I consider the first requisite of
a wise, in opposition to a cunning and temporizing statesman.
Statesmanship, as distinguished from that skilful combination of
measures which has for its object personal advancement, consists
very much in a perception of the connexion there is between the
prosperity of states, and the accordance of their laws and social
institutions with the laws of justice, and benevolence, and
temperance, which are the laws of God. The laws of God are
uniform. The general tendencies which he has inwrought into the
system will take effect, and nothing, not shaped in accordance with
these can stand. Now it is an attempt to evade the effect of these
tendencies by expedients in particular instances and for the sake of
particular ends, that has been called statesmanship; while he only is
the true statesman who sees what these tendencies are, and shapes
his laws and institutions in accordance with them. The mere
politician, if I may so designate him, perceives the movements which
take place in the different parts of society relatively to each other,
and is complacently skilful in adjusting them to his purposes, but he
fails to see that general movement by which the whole is drifted on
together, and which is bearing society to a point where elements
that he had not dreamed of will be called into action, and where his
petty expedients will become in a moment, but as the barriers of
sand which the child raises upon the beach, when the tide begins to
rise.
"I tremble for my country," said an American statesman, in a
sentence, which, though awfully ominous in the connexion in which
it was uttered, does equal honor to his head and his heart, "I
tremble for my country when I remember that God is just." In that
sentence are involved the principles of that higher statesmanship
before which the expedients of merely expert men dwindle into
nothing. He knew not how, or where, or when, the blow might fall;
but he knew that there was always a joint in the harness of injustice,
where the arrow of retribution, though it might seem to be speeding
at a venture, would surely find its way. The higher movements of
Divine Providence include the lower. Sooner or later all particular,
and for a time apparently anomalous cases are brought under its
general rules, and he has read the history of the past with little
benefit, who has failed to see how the giant machinery of that
Providence, in the intermediate spaces of which there is ample room
for the free play of human agency, takes up the results of that
agency as they are wrought out, and applies them to the execution
of its own uniform laws, and the accomplishment of its own
predicted purposes. These purposes, as declared by those divine
records whose prophecies have now become history, were often
such as no human sagacity, looking merely at second causes, could
have anticipated, such as no human power then existing could have
effected. Still, they were wrought out in conformity with that higher,
and uniform, and all-encompassing movement with reference to
which he who stands at the helm should guide the state, but to
ascertain which, he must not take his bearings from the shifting
headlands of circumstances, but must lift his eye to those eternal
principles which abide ever the same. On this subject there is written
upon the walls of the past a lesson for statesmen that needs no
interpreter. Look at Babylon. Who is it that stands before its walls,
and utters its doom? It is a despised Jew. And who is he that walks
in pride upon those walls, and as he points to that mighty city as the
centre of civilization and power, as combining every advantage of
climate and of commerce, mocks at that doom? It is a politician of
those days. The voice of the prophet is uttered, and it seems to pass
idly upon the wind. The eye of sense sees no effect. No clouds
gather, no lightnings descend. But that voice was not in vain. The
waters of desolation heard it in their distant caves, and never ceased
to rise till they had whelmed palace and tower and temple in one
undistinguished ruin. Even now that voice abides there, and hangs
as a spirit of the air over that desolation, and the Arabian hears it,
warning him not to pitch his tent there, and the wild beast of the
desart and the owl and the satyr hear it, and come up and dwell and
dance there. Look at Jerusalem. Who is he that stands upon mount
Olivet and weeps as he looks upon the city, and assigns, as the
cause of his tears, that he would often have gathered her children
together as a hen gathereth her chickens under her wings, but she
would not? Ah! what political Jew would have thought of that! He
would have turned his attention to the purposes of governors and
the intrigues of courts. Into his estimate of the causes that might
affect the prosperity of Jerusalem, the moral temper of the nation as
indicated by its rejection of Jesus of Nazareth, would not have
entered. And yet, it was from this rejection, even in the way of
natural consequence, from the want of those moral qualities which
only a regard to his teachings could have produced among them,
that the destruction of the Jews resulted. Nothing else could have
destroyed their fool-hardy confidence in God, or have allayed those
fiendish passions which led contending factions to fill the streets of
the city with dead bodies even in the midst of the siege. But they
would not have his spirit; they would not have him to reign over
them, and we know that from the moment the words dropped from
his lips, "Your house is left unto you desolate," that was a doomed
city, and no political skill could have deferred the horrors of a siege
and of a final overthrow, such as was not from the beginning of the
world, no, nor ever shall be. And not only from Babylon and
Jerusalem, but from the grave of every nation buried in antiquity,
from Nineveh, and Tyre, and Edom, and Egypt, there comes a voice
calling upon rulers to be "just, ruling in the fear of God." The true
cause of their destruction was the attitude which they assumed
towards the will, and worship, and people of God.
It is from these moral causes, between which and the result there is
no immediate, nor, to the superficial eye, perceptible connexion, that
I fear most for the stability of our institutions. It is when the sun is
shining most brightly, and the face of the sky shows, it may be, not
a single cloud, that the elements of the tornado are ascending most
rapidly; and it is when men are in prosperity and in fancied security
that they become presumptuous, and that a disastrous train of
causes is silently put in motion, as resistless as the tornado. Upon
this point of security, the eye of the true statesman is fixed. It is
here that he sees the danger and provides against it; while the mere
politician knows nothing, and sees nothing, till he begins, when it is
too late, to see the lightnings, and hear the thunders of embodied
wrath.
Can, then, the rulers of this country, in disregard of the warnings of
all past time, with a full understanding of the claims and of the
controlling agency of the great moral principles of God's
government, go on in obedience to men rather than God, and make
laws in disregard, or defiance of his will? If so, then, from the
reciprocal influence of rulers and people, our experiment of self-
government would seem to be hopeless. Then must God scourge
this people as he has scourged others. Then are the untoward
symptoms of the present time, but as the white spot that shows the
leprosy. Then will the altar of liberty decay, and the fire upon it will
go out, and there will be heard by those who watch in her temple,
as of old in the desecrated temple of God, the voice of its presiding
spirit saying, "Let us go hence," and that temple, towards which the
eyes of the nations were turned with hope, shall become the haunt
of every unclean thing, and shall only wait the hand of violence to
leave not one stone upon another that shall not be thrown down. In
view of such consequences, I cannot but feel that the solemn words
of our Saviour are as applicable to Legislators and rulers in their
public, as in their private capacity. "And I say unto you, my friends,
be not afraid of them that kill the body, and after that have no more
that they can do. But I will forewarn you whom ye shall fear: Fear
him which after he hath killed, hath power to cast into hell, yea I say
unto you, Fear him."

To His Excellency the Governor, these sentiments are addressed, as


putting him in remembrance, as he stands upon the threshold of a
new official year, of that which ought ever to be uppermost in the
mind of the Chief Magistrate of a Christian people, of the paramount
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like