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

Download Full Programming: Principles and Practice Using C++ 2nd Edition, (Ebook PDF) PDF All Chapters

Using

Uploaded by

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

Download Full Programming: Principles and Practice Using C++ 2nd Edition, (Ebook PDF) PDF All Chapters

Using

Uploaded by

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

Download Full Version ebookmass - Visit ebookmass.

com

Programming: Principles and Practice Using C++ 2nd


Edition, (Ebook PDF)

https://ebookmass.com/product/programming-principles-and-
practice-using-c-2nd-edition-ebook-pdf/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmass.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Programming: Principles and Practice Using C++ , Second


Edition Stroustrup

https://ebookmass.com/product/programming-principles-and-practice-
using-c-second-edition-stroustrup/

ebookmass.com

C Programming Language: C PROGRAMMING LANG _p2 2nd


Edition, (Ebook PDF)

https://ebookmass.com/product/c-programming-language-c-programming-
lang-_p2-2nd-edition-ebook-pdf/

ebookmass.com

Data Parallel C++: Programming Accelerated Systems Using


C++ and SYCL 2nd Edition James Reinders

https://ebookmass.com/product/data-parallel-c-programming-accelerated-
systems-using-c-and-sycl-2nd-edition-james-reinders/

ebookmass.com

The Art of Hunger: Aesthetic Autonomy and the Afterlives


of Modernism Alys Moody

https://ebookmass.com/product/the-art-of-hunger-aesthetic-autonomy-
and-the-afterlives-of-modernism-alys-moody/

ebookmass.com
Invertebrate Histology 1st Edition Elise E.B. Ladouceur
(Editor)

https://ebookmass.com/product/invertebrate-histology-1st-edition-
elise-e-b-ladouceur-editor/

ebookmass.com

Treasures - Gr 3 Unit 4-6 Mcgraw-Hill [Mcgraw-Hill]

https://ebookmass.com/product/treasures-gr-3-unit-4-6-mcgraw-hill-
mcgraw-hill/

ebookmass.com

Her Naughty Neighbor: A Curvy Woman Instalove Romance


(Naughty Nights Book 4) C.L. Cruz

https://ebookmass.com/product/her-naughty-neighbor-a-curvy-woman-
instalove-romance-naughty-nights-book-4-c-l-cruz/

ebookmass.com

Emprendimiento e innovación: diseña y planea tu negocio


Jullia Esther Hilarión Madariaga

https://ebookmass.com/product/emprendimiento-e-innovacion-disena-y-
planea-tu-negocio-jullia-esther-hilarion-madariaga/

ebookmass.com

Radio-Frequency Capacitive Discharges 1st Edition – Ebook


PDF Version

https://ebookmass.com/product/radio-frequency-capacitive-
discharges-1st-edition-ebook-pdf-version/

ebookmass.com
Probabilistic knowledge Moss

https://ebookmass.com/product/probabilistic-knowledge-moss/

ebookmass.com
Chapter 4 Computation
4.1 Computation
4.2 Objectives and tools
4.3 Expressions
4.3.1 Constant expressions
4.3.2 Operators
4.3.3 Conversions
4.4 Statements
4.4.1 Selection
4.4.2 Iteration
4.5 Functions
4.5.1 Why bother with functions?
4.5.2 Function declarations
4.6 vector
4.6.1 Traversing a vector
4.6.2 Growing a vector
4.6.3 A numeric example
4.6.4 A text example
4.7 Language features
Chapter 5 Errors
5.1 Introduction
5.2 Sources of errors
5.3 Compile-time errors
5.3.1 Syntax errors
5.3.2 Type errors
5.3.3 Non-errors
5.4 Link-time errors
5.5 Run-time errors
5.5.1 The caller deals with errors
5.5.2 The callee deals with errors
5.5.3 Error reporting
5.6 Exceptions
5.6.1 Bad arguments
5.6.2 Range errors
5.6.3 Bad input
5.6.4 Narrowing errors
5.7 Logic errors
5.8 Estimation
5.9 Debugging
5.9.1 Practical debug advice
5.10 Pre- and post-conditions
5.10.1 Post-conditions
5.11 Testing
Chapter 6 Writing a Program
6.1 A problem
6.2 Thinking about the problem
6.2.1 Stages of development
6.2.2 Strategy
6.3 Back to the calculator!
6.3.1 First attempt
6.3.2 Tokens
6.3.3 Implementing tokens
6.3.4 Using tokens
6.3.5 Back to the drawing board
6.4 Grammars
6.4.1 A detour: English grammar
6.4.2 Writing a grammar
6.5 Turning a grammar into code
6.5.1 Implementing grammar rules
6.5.2 Expressions
6.5.3 Terms
6.5.4 Primary expressions
6.6 Trying the first version
6.7 Trying the second version
6.8 Token streams
6.8.1 Implementing Token_stream
6.8.2 Reading tokens
6.8.3 Reading numbers
6.9 Program structure
Chapter 7 Completing a Program
7.1 Introduction
7.2 Input and output
7.3 Error handling
7.4 Negative numbers
7.5 Remainder: %
7.6 Cleaning up the code
7.6.1 Symbolic constants
7.6.2 Use of functions
7.6.3 Code layout
7.6.4 Commenting
7.7 Recovering from errors
7.8 Variables
7.8.1 Variables and definitions
7.8.2 Introducing names
7.8.3 Predefined names
7.8.4 Are we there yet?
Chapter 8 Technicalities: Functions, etc.
8.1 Technicalities
8.2 Declarations and definitions
8.2.1 Kinds of declarations
8.2.2 Variable and constant declarations
8.2.3 Default initialization
8.3 Header files
8.4 Scope
8.5 Function call and return
8.5.1 Declaring arguments and return type
8.5.2 Returning a value
8.5.3 Pass-by-value
8.5.4 Pass-by-const-reference
8.5.5 Pass-by-reference
8.5.6 Pass-by-value vs. pass-by-reference
8.5.7 Argument checking and conversion
8.5.8 Function call implementation
8.5.9 constexpr functions
8.6 Order of evaluation
8.6.1 Expression evaluation
8.6.2 Global initialization
8.7 Namespaces
8.7.1 using declarations and using directives
Chapter 9 Technicalities: Classes, etc.
9.1 User-defined types
9.2 Classes and members
9.3 Interface and implementation
9.4 Evolving a class
9.4.1 struct and functions
9.4.2 Member functions and constructors
9.4.3 Keep details private
9.4.4 Defining member functions
9.4.5 Referring to the current object
9.4.6 Reporting errors
9.5 Enumerations
9.5.1 “Plain” enumerations
9.6 Operator overloading
9.7 Class interfaces
9.7.1 Argument types
9.7.2 Copying
9.7.3 Default constructors
9.7.4 const member functions
9.7.5 Members and “helper functions”
9.8 The Date class

Part II Input and Output


Chapter 10 Input and Output Streams
10.1 Input and output
10.2 The I/O stream model
10.3 Files
10.4 Opening a file
10.5 Reading and writing a file
10.6 I/O error handling
10.7 Reading a single value
10.7.1 Breaking the problem into manageable
parts
10.7.2 Separating dialog from function
10.8 User-defined output operators
10.9 User-defined input operators
10.10 A standard input loop
10.11 Reading a structured file
10.11.1 In-memory representation
10.11.2 Reading structured values
10.11.3 Changing representations
Chapter 11 Customizing Input and Output
11.1 Regularity and irregularity
11.2 Output formatting
11.2.1 Integer output
11.2.2 Integer input
11.2.3 Floating-point output
11.2.4 Precision
11.2.5 Fields
11.3 File opening and positioning
11.3.1 File open modes
11.3.2 Binary files
11.3.3 Positioning in files
11.4 String streams
11.5 Line-oriented input
11.6 Character classification
11.7 Using nonstandard separators
11.8 And there is so much more
Chapter 12 A Display Model
12.1 Why graphics?
12.2 A display model
12.3 A first example
12.4 Using a GUI library
12.5 Coordinates
12.6 Shapes
12.7 Using Shape primitives
12.7.1 Graphics headers and main
12.7.2 An almost blank window
12.7.3 Axis
12.7.4 Graphing a function
12.7.5 Polygons
12.7.6 Rectangles
12.7.7 Fill
12.7.8 Text
12.7.9 Images
12.7.10 And much more
12.8 Getting this to run
12.8.1 Source files
Chapter 13 Graphics Classes
13.1 Overview of graphics classes
13.2 Point and Line
13.3 Lines
13.4 Color
13.5 Line_style
13.6 Open_polyline
13.7 Closed_polyline
13.8 Polygon
13.9 Rectangle
13.10 Managing unnamed objects
13.11 Text
13.12 Circle
13.13 Ellipse
13.14 Marked_polyline
13.15 Marks
13.16 Mark
13.17 Images
Chapter 14 Graphics Class Design
14.1 Design principles
14.1.1 Types
14.1.2 Operations
14.1.3 Naming
14.1.4 Mutability
14.2 Shape
14.2.1 An abstract class
14.2.2 Access control
14.2.3 Drawing shapes
14.2.4 Copying and mutability
14.3 Base and derived classes
14.3.1 Object layout
14.3.2 Deriving classes and defining virtual
functions
14.3.3 Overriding
14.3.4 Access
14.3.5 Pure virtual functions
14.4 Benefits of object-oriented programming
Chapter 15 Graphing Functions and Data
15.1 Introduction
15.2 Graphing simple functions
15.3 Function
15.3.1 Default Arguments
15.3.2 More examples
15.3.3 Lambda expressions
15.4 Axis
15.5 Approximation
15.6 Graphing data
15.6.1 Reading a file
15.6.2 General layout
15.6.3 Scaling data
15.6.4 Building the graph
Chapter 16 Graphical User Interfaces
16.1 User interface alternatives
16.2 The “Next” button
16.3 A simple window
16.3.1 A callback function
16.3.2 A wait loop
16.3.3 A lambda expression as a callback
16.4 Button and other Widgets
16.4.1 Widgets
16.4.2 Buttons
16.4.3 In_box and Out_box
16.4.4 Menus
16.5 An example
16.6 Control inversion
16.7 Adding a menu
16.8 Debugging GUI code

Part III Data and Algorithms


Chapter 17 Vector and Free Store
17.1 Introduction
17.2 vector basics
17.3 Memory, addresses, and pointers
17.3.1 The sizeof operator
17.4 Free store and pointers
17.4.1 Free-store allocation
17.4.2 Access through pointers
17.4.3 Ranges
17.4.4 Initialization
17.4.5 The null pointer
17.4.6 Free-store deallocation
17.5 Destructors
17.5.1 Generated destructors
17.5.2 Destructors and free store
17.6 Access to elements
17.7 Pointers to class objects
17.8 Messing with types: void* and casts
17.9 Pointers and references
17.9.1 Pointer and reference parameters
17.9.2 Pointers, references, and inheritance
17.9.3 An example: lists
17.9.4 List operations
17.9.5 List use
17.10 The this pointer
17.10.1 More link use
Chapter 18 Vectors and Arrays
18.1 Introduction
18.2 Initialization
18.3 Copying
18.3.1 Copy constructors
18.3.2 Copy assignments
18.3.3 Copy terminology
18.3.4 Moving
18.4 Essential operations
18.4.1 Explicit constructors
18.4.2 Debugging constructors and destructors
18.5 Access to vector elements
18.5.1 Overloading on const
18.6 Arrays
18.6.1 Pointers to array elements
18.6.2 Pointers and arrays
18.6.3 Array initialization
18.6.4 Pointer problems
18.7 Examples: palindrome
18.7.1 Palindromes using string
18.7.2 Palindromes using arrays
18.7.3 Palindromes using pointers
Chapter 19 Vector, Templates, and Exceptions
19.1 The problems
19.2 Changing size
19.2.1 Representation
19.2.2 reserve and capacity
19.2.3 resize
19.2.4 push_back
19.2.5 Assignment
19.2.6 Our vector so far
19.3 Templates
19.3.1 Types as template parameters
19.3.2 Generic programming
19.3.3 Concepts
19.3.4 Containers and inheritance
19.3.5 Integers as template parameters
19.3.6 Template argument deduction
19.3.7 Generalizing vector
19.4 Range checking and exceptions
19.4.1 An aside: design considerations
19.4.2 A confession: macros
19.5 Resources and exceptions
19.5.1 Potential resource management problems
19.5.2 Resource acquisition is initialization
19.5.3 Guarantees
19.5.4 unique_ptr
19.5.5 Return by moving
19.5.6 RAII for vector
Chapter 20 Containers and Iterators
20.1 Storing and processing data
20.1.1 Working with data
20.1.2 Generalizing code
20.2 STL ideals
20.3 Sequences and iterators
20.3.1 Back to the example
20.4 Linked lists
20.4.1 List operations
20.4.2 Iteration
20.5 Generalizing vector yet again
20.5.1 Container traversal
20.5.2 auto
20.6 An example: a simple text editor
20.6.1 Lines
20.6.2 Iteration
20.7 vector, list, and string
20.7.1 insert and erase
20.8 Adapting our vector to the STL
20.9 Adapting built-in arrays to the STL
20.10 Container overview
20.10.1 Iterator categories
Chapter 21 Algorithms and Maps
21.1 Standard library algorithms
21.2 The simplest algorithm: find()
21.2.1 Some generic uses
21.3 The general search: find_if()
21.4 Function objects
21.4.1 An abstract view of function objects
21.4.2 Predicates on class members
21.4.3 Lambda expressions
21.5 Numerical algorithms
21.5.1 Accumulate
21.5.2 Generalizing accumulate()
21.5.3 Inner product
21.5.4 Generalizing inner_product()
21.6 Associative containers
21.6.1 map
21.6.2 map overview
21.6.3 Another map example
21.6.4 unordered_map
21.6.5 set
21.7 Copying
21.7.1 Copy
21.7.2 Stream iterators
21.7.3 Using a set to keep order
21.7.4 copy_if
21.8 Sorting and searching
21.9 Container algorithms

Part IV Broadening the View


Chapter 22 Ideals and History
22.1 History, ideals, and professionalism
22.1.1 Programming language aims and
philosophies
22.1.2 Programming ideals
22.1.3 Styles/paradigms
22.2 Programming language history overview
22.2.1 The earliest languages
22.2.2 The roots of modern languages
22.2.3 The Algol family
22.2.4 Simula
22.2.5 C
22.2.6 C++
22.2.7 Today
22.2.8 Information sources
Chapter 23 Text Manipulation
23.1 Text
23.2 Strings
23.3 I/O streams
23.4 Maps
23.4.1 Implementation details
23.5 A problem
23.6 The idea of regular expressions
23.6.1 Raw string literals
23.7 Searching with regular expressions
23.8 Regular expression syntax
23.8.1 Characters and special characters
23.8.2 Character classes
23.8.3 Repeats
23.8.4 Grouping
23.8.5 Alternation
23.8.6 Character sets and ranges
23.8.7 Regular expression errors
23.9 Matching with regular expressions
23.10 References
Chapter 24 Numerics
24.1 Introduction
24.2 Size, precision, and overflow
24.2.1 Numeric limits
24.3 Arrays
24.4 C-style multidimensional arrays
24.5 The Matrix library
24.5.1 Dimensions and access
24.5.2 1D Matrix
24.5.3 2D Matrix
24.5.4 Matrix I/O
24.5.5 3D Matrix
24.6 An example: solving linear equations
24.6.1 Classical Gaussian elimination
24.6.2 Pivoting
24.6.3 Testing
24.7 Random numbers
24.8 The standard mathematical functions
24.9 Complex numbers
24.10 References
Chapter 25 Embedded Systems Programming
25.1 Embedded systems
25.2 Basic concepts
25.2.1 Predictability
25.2.2 Ideals
25.2.3 Living with failure
25.3 Memory management
25.3.1 Free-store problems
25.3.2 Alternatives to the general free store
25.3.3 Pool example
25.3.4 Stack example
25.4 Addresses, pointers, and arrays
25.4.1 Unchecked conversions
25.4.2 A problem: dysfunctional interfaces
25.4.3 A solution: an interface class
25.4.4 Inheritance and containers
25.5 Bits, bytes, and words
25.5.1 Bits and bit operations
25.5.2 bitset
25.5.3 Signed and unsigned
25.5.4 Bit manipulation
25.5.5 Bitfields
25.5.6 An example: simple encryption
25.6 Coding standards
25.6.1 What should a coding standard be?
25.6.2 Sample rules
25.6.3 Real coding standards
Chapter 26 Testing
26.1 What we want
26.1.1 Caveat
26.2 Proofs
26.3 Testing
26.3.1 Regression tests
26.3.2 Unit tests
26.3.3 Algorithms and non-algorithms
26.3.4 System tests
26.3.5 Finding assumptions that do not hold
26.4 Design for testing
26.5 Debugging
26.6 Performance
26.6.1 Timing
26.7 References
Chapter 27 The C Programming Language
27.1 C and C++: siblings
27.1.1 C/C++ compatibility
27.1.2 C++ features missing from C
27.1.3 The C standard library
27.2 Functions
27.2.1 No function name overloading
27.2.2 Function argument type checking
27.2.3 Function definitions
27.2.4 Calling C from C++ and C++ from C
27.2.5 Pointers to functions
27.3 Minor language differences
27.3.1 struct tag namespace
27.3.2 Keywords
27.3.3 Definitions
27.3.4 C-style casts
27.3.5 Conversion of void*
27.3.6 enum
27.3.7 Namespaces
27.4 Free store
27.5 C-style strings
27.5.1 C-style strings and const
27.5.2 Byte operations
27.5.3 An example: strcpy()
27.5.4 A style issue
27.6 Input/output: stdio
27.6.1 Output
27.6.2 Input
27.6.3 Files
27.7 Constants and macros
27.8 Macros
27.8.1 Function-like macros
27.8.2 Syntax macros
27.8.3 Conditional compilation
27.9 An example: intrusive containers

Part V Appendices
Appendix A Language Summary
A.1 General
A.1.1 Terminology
A.1.2 Program start and termination
A.1.3 Comments
A.2 Literals
A.2.1 Integer literals
A.2.2 Floating-point-literals
A.2.3 Boolean literals
A.2.4 Character literals
A.2.5 String literals
A.2.6 The pointer literal
A.3 Identifiers
A.3.1 Keywords
A.4 Scope, storage class, and lifetime
A.4.1 Scope
A.4.2 Storage class
A.4.3 Lifetime
A.5 Expressions
A.5.1 User-defined operators
A.5.2 Implicit type conversion
A.5.3 Constant expressions
A.5.4 sizeof
A.5.5 Logical expressions
A.5.6 new and delete
A.5.7 Casts
A.6 Statements
A.7 Declarations
A.7.1 Definitions
A.8 Built-in types
A.8.1 Pointers
A.8.2 Arrays
A.8.3 References
A.9 Functions
A.9.1 Overload resolution
A.9.2 Default arguments
A.9.3 Unspecified arguments
A.9.4 Linkage specifications
A.10 User-defined types
A.10.1 Operator overloading
A.11 Enumerations
A.12 Classes
A.12.1 Member access
A.12.2 Class member definitions
A.12.3 Construction, destruction, and copy
A.12.4 Derived classes
A.12.5 Bitfields
A.12.6 Unions
A.13 Templates
A.13.1 Template arguments
A.13.2 Template instantiation
A.13.3 Template member types
A.14 Exceptions
A.15 Namespaces
A.16 Aliases
A.17 Preprocessor directives
A.17.1 #include
A.17.2 #define
Appendix B Standard Library Summary
B.1 Overview
B.1.1 Header files
B.1.2 Namespace std
B.1.3 Description style
B.2 Error handling
B.2.1 Exceptions
B.3 Iterators
B.3.1 Iterator model
B.3.2 Iterator categories
B.4 Containers
B.4.1 Overview
B.4.2 Member types
B.4.3 Constructors, destructors, and assignments
B.4.4 Iterators
B.4.5 Element access
B.4.6 Stack and queue operations
B.4.7 List operations
B.4.8 Size and capacity
B.4.9 Other operations
B.4.10 Associative container operations
B.5 Algorithms
B.5.1 Nonmodifying sequence algorithms
B.5.2 Modifying sequence algorithms
B.5.3 Utility algorithms
B.5.4 Sorting and searching
B.5.5 Set algorithms
B.5.6 Heaps
B.5.7 Permutations
B.5.8 min and max
B.6 STL utilities
B.6.1 Inserters
B.6.2 Function objects
B.6.3 pair and tuple
B.6.4 initializer_list
B.6.5 Resource management pointers
B.7 I/O streams
B.7.1 I/O streams hierarchy
B.7.2 Error handling
B.7.3 Input operations
B.7.4 Output operations
B.7.5 Formatting
B.7.6 Standard manipulators
B.8 String manipulation
B.8.1 Character classification
B.8.2 String
B.8.3 Regular expression matching
B.9 Numerics
B.9.1 Numerical limits
B.9.2 Standard mathematical functions
B.9.3 Complex
B.9.4 valarray
B.9.5 Generalized numerical algorithms
B.9.6 Random numbers
B.10 Time
B.11 C standard library functions
B.11.1 Files
B.11.2 The printf() family
B.11.3 C-style strings
B.11.4 Memory
B.11.5 Date and time
B.11.6 Etc.
B.12 Other libraries
Appendix C Getting Started with Visual Studio
C.1 Getting a program to run
C.2 Installing Visual Studio
C.3 Creating and running a program
C.3.1 Create a new project
C.3.2 Use the std_lib_facilities.h header file
C.3.3 Add a C++ source file to the project
C.3.4 Enter your source code
C.3.5 Build an executable program
C.3.6 Execute the program
C.3.7 Save the program
C.4 Later
Appendix D Installing FLTK
D.1 Introduction
D.2 Downloading FLTK
D.3 Installing FLTK
D.4 Using FLTK in Visual Studio
D.5 Testing if it all worked
Appendix E GUI Implementation
E.1 Callback implementation
E.2 Widget implementation
E.3 Window implementation
E.4 Vector_ref
E.5 An example: manipulating Widgets
Glossary
Bibliography
Index
Preface
“Damn the torpedoes! Full speed ahead.”
—Admiral Farragut

Programming is the art of expressing solutions to problems


so that a computer can execute those solutions. Much of the
effort in programming is spent finding and refining solutions.
Often, a problem is only fully understood through the
process of programming a solution for it.
This book is for someone who has never programmed
before but is willing to work hard to learn. It helps you
understand the principles and acquire the practical skills of
programming using the C++ programming language. My
aim is for you to gain sufficient knowledge and experience
to perform simple useful programming tasks using the best
up-to-date techniques. How long will that take? As part of a
first-year university course, you can work through this book
in a semester (assuming that you have a workload of four
courses of average difficulty). If you work by yourself, don’t
expect to spend less time than that (maybe 15 hours a
week for 14 weeks).
Three months may seem a long time, but there’s a lot to
learn and you’ll be writing your first simple programs after
about an hour. Also, all learning is gradual: each chapter
introduces new useful concepts and illustrates them with
examples inspired by real-world uses. Your ability to express
ideas in code — getting a computer to do what you want it
to do — gradually and steadily increases as you go along. I
never say, “Learn a month’s worth of theory and then see if
you can use it.”
Why would you want to program? Our civilization runs on
software. Without understanding software you are reduced
to believing in “magic” and will be locked out of many of the
most interesting, profitable, and socially useful technical
fields of work. When I talk about programming, I think of the
whole spectrum of computer programs from personal
computer applications with GUIs (graphical user interfaces),
through engineering calculations and embedded systems
control applications (such as digital cameras, cars, and cell
phones), to text manipulation applications as found in many
humanities and business applications. Like mathematics,
programming — when done well — is a valuable intellectual
exercise that sharpens our ability to think. However, thanks
to feedback from the computer, programming is more
concrete than most forms of math, and therefore accessible
to more people. It is a way to reach out and change the
world – ideally for the better. Finally, programming can be
great fun.
Why C++? You can’t learn to program without a
programming language, and C++ directly supports the key
concepts and techniques used in real-world software. C++
is one of the most widely used programming languages,
found in an unsurpassed range of application areas. You find
C++ applications everywhere from the bottom of the
oceans to the surface of Mars. C++ is precisely and
comprehensively defined by a nonproprietary international
standard. Quality and/or free implementations are available
on every kind of computer. Most of the programming
concepts that you will learn using C++ can be used directly
in other languages, such as C, C#, Fortran, and Java. Finally,
I simply like C++ as a language for writing elegant and
efficient code.
This is not the easiest book on beginning programming; it
is not meant to be. I just aim for it to be the easiest book
from which you can learn the basics of real-world
programming. That’s quite an ambitious goal because much
modern software relies on techniques considered advanced
just a few years ago.
My fundamental assumption is that you want to write
programs for the use of others, and to do so responsibly,
providing a decent level of system quality; that is, I assume
that you want to achieve a level of professionalism.
Consequently, I chose the topics for this book to cover what
is needed to get started with real-world programming, not
just what is easy to teach and learn. If you need a technique
to get basic work done right, I describe it, demonstrate
concepts and language facilities needed to support the
technique, provide exercises for it, and expect you to work
on those exercises. If you just want to understand toy
programs, you can get along with far less than I present. On
the other hand, I won’t waste your time with material of
marginal practical importance. If an idea is explained here,
it’s because you’ll almost certainly need it.
If your desire is to use the work of others without
understanding how things are done and without adding
significantly to the code yourself, this book is not for you. If
so, please consider whether you would be better served by
another book and another language. If that is approximately
your view of programming, please also consider from where
you got that view and whether it in fact is adequate for your
needs. People often underestimate the complexity of
programming as well as its value. I would hate for you to
acquire a dislike for programming because of a mismatch
between what you need and the part of the software reality
I describe. There are many parts of the “information
technology” world that do not require knowledge of
programming. This book is aimed to serve those who do
want to write or understand nontrivial programs.
Because of its structure and practical aims, this book can
also be used as a second book on programming for
someone who already knows a bit of C++ or for someone
who programs in another language and wants to learn C++.
If you fit into one of those categories, I refrain from guessing
how long it will take you to read this book, but I do
encourage you to do many of the exercises. This will help
you to counteract the common problem of writing programs
in older, familiar styles rather than adopting newer
techniques where these are more appropriate. If you have
learned C++ in one of the more traditional ways, you’ll find
something surprising and useful before you reach Chapter 7.
Unless your name is Stroustrup, what I discuss here is not
“your father’s C++.”
Programming is learned by writing programs. In this,
programming is similar to other endeavors with a practical
component. You cannot learn to swim, to play a musical
instrument, or to drive a car just from reading a book — you
must practice. Nor can you learn to program without reading
and writing lots of code. This book focuses on code
examples closely tied to explanatory text and diagrams. You
need those to understand the ideals, concepts, and
principles of programming and to master the language
constructs used to express them. That’s essential, but by
itself, it will not give you the practical skills of programming.
For that, you need to do the exercises and get used to the
tools for writing, compiling, and running programs. You need
to make your own mistakes and learn to correct them. There
is no substitute for writing code. Besides, that’s where the
fun is!
On the other hand, there is more to programming — much
more — than following a few rules and reading the manual.
This book is emphatically not focused on “the syntax of
C++.” Understanding the fundamental ideals, principles,
and techniques is the essence of a good programmer. Only
well-designed code has a chance of becoming part of a
correct, reliable, and maintainable system. Also, “the
Exploring the Variety of Random
Documents with Different Content
hideous contortions. Against this scene objections on the score of
offended propriety may with most reason be brought. They come
from an Englishman, a man, therefore, not readily to be suspected of
false delicacy. As already hinted, he supports his objections by very
good arguments. “All feelings and passions,” he says, “with which
others can have little sympathy, become offensive if too violently
expressed.”[28] “It is for the same reason that to cry out with bodily
pain, how intolerable soever, appears always unmanly and
unbecoming. There is, however, a good deal of sympathy even with
bodily pain. If I see a stroke aimed and just ready to fall upon the leg
or arm of another person, I naturally shriek and draw back my own
leg or my own arm; and when it does fall, I feel it in some measure
and am hurt by it as well as the sufferer. My hurt, however, is no
doubt excessively slight, and, upon that account, if he makes any
violent outcry, as I cannot go along with him, I never fail to despise
him.”
Nothing is more deceptive than the laying down of general laws for
our emotions. Their web is so fine and intricate that the most
cautious speculation is hardly able to take up a single thread and
trace it through all its interlacings. And if it could, what should we
gain? There is in nature no single, unmixed emotion. With every one
spring up a thousand others, the most insignificant of which
essentially modifies the original one, so that exception after
exception arises until our supposed universal law shrinks into a mere
personal experience in a few individual cases. We despise a man,
says the Englishman, whom we hear crying out under bodily pain.
But not always; not the first time; not when we see that the sufferer
does all in his power to suppress expressions of pain; not when we
know him to be otherwise a man of resolution: still less when we see
him giving proof of firmness in the midst of his suffering; when we
see that pain, though it extort a cry, can extort nothing further; that
he submits to a continuance of the anguish rather than yield a jot of
his opinions or resolves, although such a concession would end his
woes. All this we find in Philoctetes. To the old Greek mind moral
greatness consisted in unchanging love of friends as well as
unfaltering hatred of enemies. This greatness Philoctetes preserves
through all his tortures. His own griefs have not so exhausted his
tears that he has none to shed over the fate of his old friends. His
sufferings have not so enervated him that, to be free from them, he
would forgive his enemies and lend himself to their selfish ends. And
did this man of rock deserve to be despised by the Athenians,
because the waves, that could not shake him, wrung from him a
moan?
I confess to having little taste for the philosophy of Cicero in
general, but particularly distasteful to me are his views with regard to
the endurance of bodily pain set forth in the second book of his
Tusculan Disputations. One would suppose, from his abhorrence of
all expressions of bodily pain, that he was training a gladiator. He
seems to see in such expressions only impatience, not considering
that they are often wholly involuntary, and that true courage can be
shown in none but voluntary actions. In the play of Sophocles he
hears only the cries and complaints of Philoctetes and overlooks
altogether his otherwise resolute bearing. Else what excuse for his
rhetorical outbreak against the poets? “They would make us
effeminate by introducing the bravest of their warriors as
complaining.” They should complain, for the theatre is no arena. The
condemned or hired gladiator was bound to do and bear with grace.
No sound of lamentation must be heard, no painful contortion seen.
His wounds and death were to amuse the spectators, and art must
therefore teach the suppression of all feeling. The least manifestation
of it might have aroused compassion, and compassion often excited
would soon have put an end to the cruel shows. But what is to be
avoided in the arena is the very object of the tragic stage, and here,
therefore, demeanor of exactly the opposite kind is required. The
heroes on the stage must show feeling, must express their sufferings,
and give free course to nature. Any appearance of art and constraint
represses sympathy. Boxers in buskin can at most excite our
admiration. This term may fitly be applied to the so-called Senecan
tragedies. I am convinced that the gladiatorial shows were the chief
reason why the Romans never attained even to mediocrity in their
tragedies. In the bloody amphitheatre the spectators lost all
acquaintance with nature. A Ctesias might have studied his art there,
never a Sophocles. The greatest tragic genius, accustomed to these
artificial death scenes, could not help degenerating into bombast and
rodomontade. But as these were incapable of inspiring true heroism,
so were the complaints of Philoctetes incapable of producing
effeminacy. The complaints are human, while the deeds are heroic.
Both together make the human hero, who is neither effeminate nor
callous, but appears first the one and then the other, as now Nature
sways him, and now principle and duty triumph. This is the highest
type that wisdom can create and art imitate.
4. Sophocles, not content with securing his suffering Philoctetes
against contempt, has even shielded him beforehand from such
hostile criticism as that employed by the Englishman. Though we
may not always despise a man who cries out under bodily pain, we
certainly do not feel that degree of sympathy with him which his cry
seems to demand. How then should those comport themselves who
are about this screaming Philoctetes? Should they appear to be
greatly moved? That were contrary to nature. Should they seem as
cold and embarrassed as the by-stander on such occasions is apt
actually to be? Such a want of harmony would offend the spectator.
Sophocles, as I have said, anticipated this and guarded against it in
the following way,—he gave to each of the by-standers a subject of
personal interest. They are not solely occupied with Philoctetes and
his cries. The attention of the spectator, therefore, is directed to the
change wrought in each person’s own views and designs by the
sympathy excited in him, whether strong or weak, not to the
disproportion between the sympathy itself and its exciting cause.
Neoptolemus and the chorus have deceived the unhappy Philoctetes,
and while perceiving the despair they are bringing upon him they
behold him overpowered by one of his accesses of pain. Even should
this arouse no great degree of sympathy in them, it must at least lead
them to self-examination and prevent their increasing by treachery a
misery which they cannot but respect. This the spectator looks for;
nor is his expectation disappointed by the magnanimous
Neoptolemus. Had Philoctetes been master of his suffering,
Neoptolemus would have persevered in his deceit. Philoctetes,
deprived by pain of all power of dissimulation, necessary as that
seems to prevent his future travelling companion from repenting too
soon of his promise to take him with him, Philoctetes, by his
naturalness, recalls Neoptolemus to nature. The conversion is
admirable, and all the more affecting for being brought about by
unaided human nature. The Frenchman had recourse again here to
the bright eyes. “De mes déguisements que penserait Sophie?” says
the son of Achilles. But I will think no more of this parody.
Sophocles, in “The Trachiniæ,” makes use of this same expedient
of combining in the by-standers another emotion with the
compassion excited by a cry of physical pain. The pain of Hercules
has no enervating effect, but drives him to madness. He thirsts for
vengeance, and, in his frenzy, has already seized upon Lichas and
dashed him in pieces against the rock. The chorus is composed of
women who are naturally overpowered with fear and horror. Their
terror, and the doubt whether a god will hasten to Hercules’ relief, or
whether he will fall a victim to his misfortune, make the chief interest
of the piece with but a slight tinge of compassion. As soon as the
issue has been decided by the oracle, Hercules grows calm, and all
other feelings are lost in our admiration of his final decision. But we
must not forget, when comparing the suffering Hercules with the
suffering Philoctetes, that one is a demi-god, the other but a man.
The man is never ashamed to complain; but the demi-god feels
shame that his mortal part has so far triumphed over his immortal,
that he should weep and groan like a girl.[29] We moderns do not
believe in demi-gods, but require our most insignificant hero to feel
and act like one.
That an actor can imitate the cries and convulsions of pain so
closely as to produce illusion, I neither deny nor affirm. If our actors
cannot, I should want to know whether Garrick found it equally
impossible; and, if he could not succeed, I should still have the right
to assume a degree of perfection in the acting and declamation of the
ancients of which we of to-day can form no idea.
V.

Some critics of antiquity argue that the Laocoon, though a work of


Greek art, must date from the time of the emperors, because it was
copied from the Laocoon of Virgil. Of the older scholars who have
held this opinion I will mention only Bartolomæus Martiani,[30] and
of the moderns, Montfaucon.[31] They doubtless found such
remarkable agreement between the work of art and the poem that
they could not believe the same circumstances, by no means
selfsuggesting ones, should have occurred by accident to both
sculptor and poet. The question then arose to whom the honor of
invention belonged, and they assumed the probabilities to be
decidedly in favor of the poet.
They appear, however, to have forgotten that a third alternative is
possible. The artist may not have copied the poet any more than the
poet the artist; but both perhaps drew their material from some older
source, which, Macrobius suggests, might have been Pisander.[32]
For, while the works of this Greek writer were still in existence, the
fact was familiar to every schoolboy that the Roman poet’s whole
second book, the entire conquest and destruction of Troy, was not so
much imitated as literally translated from the older writer. If then
Pisander was Virgil’s predecessor in the history of Laocoon also, the
Greek artists did not need to draw their material from a Latin poet,
and this theory of the date of the group loses its support.
If I were forced to maintain the opinion of Martiani and
Montfaucon, I should escape from the difficulty in this way.
Pisander’s poems are lost, and we can never know with certainty how
he told the story of Laocoon. Probably, however, he narrated it with
the same attendant circumstances of which we still find traces in the
Greek authors. Now these do not in the least agree with the version
of Virgil, who must have recast the Greek tradition to suit himself.
The fate of Laocoon, as he tells it, is quite his own invention, so that
the artists, if their representation harmonize with his, may fairly be
supposed to have lived after his time, and have used his description
as their model.
Quintus Calaber indeed, like Virgil, makes Laocoon express
suspicion of the wooden horse; but the wrath of Minerva, which he
thereby incurs, is very differently manifested. As the Trojan utters
his warning, the earth trembles beneath him, pain and terror fall
upon him; a burning pain rages in his eyes; his brain gives way; he
raves; he becomes blind. After his blindness, since he still continues
to advise the burning of the wooden horse, Minerva sends two
terrible dragons, which, however, attack only Laocoon’s children. In
vain they stretch out their hands to their father. The poor blind man
cannot help them. They are torn and mangled, and the serpents glide
away into the ground, doing no injury to Laocoon himself. That this
was not peculiar to Quintus,[33] but must have been generally
accepted, appears from a passage in Lycophron, where these
serpents receive the name of “childeaters.”[34]
But if this circumstance were generally accepted among the
Greeks, Greek artists would hardly have ventured to depart from it.
Or, if they made variations, these would not be likely to be the same
as those of a Roman poet, had they not known him and perhaps been
especially commissioned to use him as their model. We must insist
on this point, I think, if we would uphold Martiani and Montfaucon.
Virgil is the first and only one[35] who represents both father and
children as devoured by the serpents; the sculptors have done this
also, although, as Greeks, they should not; probably, therefore, they
did it in consequence of Virgil’s example.
I am well aware that this probability falls far short of historical
certainty. But since I mean to draw no historical conclusions from it,
we may be allowed to use it as an hypothesis on which to base our
remarks. Let us suppose, then, that the sculptors used Virgil as their
model, and see in what way they would have copied him. The cry has
been already discussed. A further comparison may perhaps lead to
not less instructive results.
The idea of coiling the murderous serpents about both father and
sons, tying them thus into one knot, is certainly a very happy one,
and betrays great picturesqueness of fancy. Whose was it? the poet’s
or the artist’s? Montfaucon thinks it is not to be found in the poem;
[36]
but, in my opinion, he has not read the passage with sufficient
care.
Illi agmine certo
Laocoonta petunt, et primum parva duorum
Corpora natorum serpens amplexus uterque
Implicat et miseros morsu depascitur artus.
Post ipsum, auxilio subeuntem et tela ferentem,
Corripiunt spirisque ligant ingentibus.[37]

The poet has described the serpents as being of a wonderful


length. They have wound their coils about the boys and seize the
father also (corripiunt) as he comes to their aid. Owing to their great
length they could not in an instant have disengaged themselves from
the boys. There must therefore have been a moment when the heads
and forward parts of the bodies had attacked the father while the
boys were still held imprisoned in the hindmost coils. Such a
moment is unavoidable in the progress of the poetic picture; and the
poet makes it abundantly manifest, though that was not the time to
describe it in detail. A passage in Donatus[38] seems to prove that the
old commentators were conscious of it; and there was still less
likelihood of its escaping the notice of artists whose trained eye was
quick to perceive any thing that could be turned to their advantage.
The poet carefully leaves Laocoon’s arms free that he may have the
full use of his hands.
Ille simul manibus tendit divellere nodos.[39]

In this point the artist must necessarily have followed him; for
nothing contributes more to the expression of life and motion than
the action of the hands. In representations of passion, especially, the
most speaking countenance is ineffective without it. Arms fastened
close to the body by the serpents’ coils would have made the whole
group cold and dead. We consequently see them in full activity, both
in the main figure and the lesser ones, and most active where for the
moment the pain is sharpest.
With the exception of this freedom of the arms, there was,
however, nothing in the poet’s manner of coiling the serpents which
could be turned to account by the artists. Virgil winds them twice
round the body and twice round the neck of Laocoon, and lets their
heads tower high above him.
Bis medium amplexi, bis collo squamea circum
Terga dati, superant capite et cervicibus altis.[40]

This description satisfies our imagination completely. The noblest


parts of the body are compressed to suffocation, and the poison is
aimed directly at the face. It furnished, however, no picture for the
artist, who would show the physical effects of the poison and the
pain. To render these conspicuous, the nobler parts of the body must
be left as free as possible, subjected to no outward pressure which
would change and weaken the play of the suffering nerves and
laboring muscles. The double coils would have concealed the whole
trunk and rendered invisible that most expressive contraction of the
abdomen. What of the body would be distinguishable above or below
or between the coils would have been swollen and compressed, not
by inward pain but by outward violence. So many rings about the
neck would have destroyed the pyramidal shape of the group which
is now pleasing to the eye, while the pointed heads of the serpents
projecting far above this huge mass, would have been such a
violation of the rules of proportion that the effect of the whole would
have been made repulsive in the extreme. There have been designers
so devoid of perception as to follow the poet implicitly. One example
of the hideous result may be found among the illustrations by
Francis Cleyn.[41] The old sculptors saw at a glance that their art
required a totally different treatment. They transferred all the coils
from the trunk and neck to the thighs and feet, parts which might be
concealed and compressed without injury to the expression. By this
means they also conveyed the idea of arrested flight, and a certain
immobility very favorable to the arbitrary continuance of one
posture.
I know not how it happens that the critics have passed over in
silence this marked difference between the coils in the marble and in
the poem. It reveals the wisdom of the artist quite as much as
another difference which they all comment upon, though rather by
way of excuse than of praise,—the difference in the dress. Virgil’s
Laocoon is in his priestly robes, while in the group he, as well as his
two sons, appears completely naked. Some persons, it is said, find a
great incongruity in the fact that a king’s son, a priest, should be
represented naked when offering a sacrifice. To this the critics
answer in all seriousness that it is, to be sure, a violation of usage but
that the artists were driven to it from inability to give their figures
suitable clothing. Sculpture, they say, cannot imitate stuffs. Thick
folds produce a bad effect. Of two evils they have therefore chosen
the lesser, and preferred to offend against truth rather than be
necessarily faulty in drapery.[42] The old artists might have laughed at
the objection, but I know not what they would have said to this
manner of answering it. No greater insult could be paid to art.
Suppose sculpture could imitate different textures as well as
painting, would Laocoon necessarily have been draped? Should we
lose nothing by drapery? Has a garment, the work of slavish hands,
as much beauty as an organized body, the work of eternal wisdom?
Does the imitation of the one require the same skill, involve the same
merit, bring the same honor as the imitation of the other? Do our
eyes require but to be deceived, and is it a matter of indifference to
them with what they are deceived?
In poetry a robe is no robe. It conceals nothing. Our imagination
sees through it in every part. Whether Virgil’s Laocoon be clothed or
not, the agony in every fibre of his body is equally visible. The brow is
bound with the priestly fillet, but not concealed. Nay, so far from
being a hinderance, the fillet rather strengthens our impression of
the sufferer’s agony.
Perfusus sanie vittas atroque veneno.[43]

His priestly dignity avails him nothing. The very badge of it, which
wins him universal consideration and respect, is saturated and
desecrated with the poisonous slaver.
But this subordinate idea the artist had to sacrifice to the general
effect. Had he retained even the fillet, his work would have lost in
expression from the partial concealment of the brow which is the
seat of expression. As in the case of the cry he sacrificed expression
to beauty, he here sacrificed conventionality to expression.
Conventionality, indeed, was held of small account among the
ancients. They felt that art, in the attainment of beauty, its true end,
could dispense with conventionalities altogether. Necessity invented
clothes, but what has art to do with necessity? There is a beauty of
drapery, I admit; but it is nothing as compared with the beauty of the
human form. Will he who can attain to the greater rest content with
the lesser? I fear that the most accomplished master in drapery, by
his very dexterity, proves his weakness.
VI.

My supposition that the artists imitated the poet is no


disparagement to them. On the contrary the manner of their
imitation reflects the greatest credit on their wisdom. They followed
the poet without suffering him in the smallest particular to mislead
them. A model was set them, but the task of transferring it from one
art into another gave them abundant opportunity for independent
thought. The originality manifested in their deviations from the
model proves them to have been no less great in their art than the
poet was in his.
Now, reversing the matter, I will suppose the poet to be working
after the model set him by the artists. This is a supposition
maintained by various scholars.[44] I know of no historical arguments
in favor of their opinion. The work appeared to them of such
exceeding beauty that they could not believe it to be of comparatively
recent date. It must have been made when art was at its perfection,
because it was worthy of that period.
We have seen that, admirable as Virgil’s picture is, there are yet
traits in it unavailable for the artist. The saying therefore requires
some modification, that a good poetical description must make a
good picture, and that a poet describes well only in so far as his
details may be used by the artist. Even without the proof furnished
by examples, we should be inclined to predicate such limitation from
a consideration of the wider sphere of poetry, the infinite range of
our imagination, and the intangibility of its images. These may stand
side by side in the greatest number and variety without concealment
or detriment to any, just as the objects themselves or their natural
symbols would in the narrow limits of time or space.
But if the smaller cannot contain the greater it can be contained in
the greater. In other words, if not every trait employed by the
descriptive poet can produce an equally good effect on canvas or in
marble, can every trait of the artist be equally effective in the work of
the poet? Undoubtedly; for what pleases us in a work of art pleases
not the eye, but the imagination through the eye. The same picture,
whether presented to the imagination by arbitrary or natural signs,
must always give us a similar pleasure, though not always in the
same degree.
But even granting this, I confess that the idea of Virgil’s having
imitated the artists is more inconceivable to me than the contrary
hypothesis. If the artists copied the poet, I can account for all their
deviations. Differences would necessarily have arisen, because many
traits employed by him with good effect would in their work have
been objectionable. But why such deviations in the poet? Would he
not have given us an admirable picture by copying the group
faithfully in every particular?[45]
I can perfectly understand how his fancy, working independently,
should have suggested to him this and that feature, but I see no
reason why his judgment should have thought it necessary to
transform the beauties that were before his eyes into these differing
ones.
It even seems to me that, had Virgil used this group as his model,
he could hardly have contented himself with leaving the general
embrace of the three bodies within the serpents’ folds to be thus
guessed at. The impression upon his eye would have been so vivid
and admirable, that he could not have failed to give the position
greater prominence in his description. As I have said, that was not
the time to dwell upon its details; but the addition of a single word
might have put a decisive emphasis upon it, even in the shadow in
which the poet was constrained to leave it. What the artist could
present without that word, the poet would not have failed to express
by it, had the work of art been before him.
The artist had imperative reasons for not allowing the sufferings of
his Laocoon to break out into cries. But if the poet had had before
him in the marble this touching union of pain with beauty, he would
certainly have been under no necessity of disregarding the idea of
manly dignity and magnanimous patience arising from it and making
his Laocoon suddenly startle us with that terrible cry. Richardson
says that Virgil’s Laocoon needed to scream, because the poet’s
object was not so much to excite compassion for him as to arouse
fear and horror among the Trojans. This I am ready to grant,
although Richardson appears not to have considered that the poet is
not giving the description in his own person, but puts it into the
mouth of Æneas, who, in his narration to Dido, spared no pains to
arouse her compassion. The cry, however, is not what surprises me,
but the absence of all intermediate stages of emotion, which the
marble could not have failed to suggest to the poet if, as we are
supposing, he had used that as his model. Richardson goes on to say,
that the story of Laocoon was meant only as an introduction to the
pathetic description of the final destruction of Troy, and that the poet
was therefore anxious not to divert to the misfortunes of a private
citizen the attention which should be concentrated on the last
dreadful night of a great city.[46] But this is a painter’s point of view,
and here inadmissible. In the poem, the fate of Laocoon and the
destruction of the city do not stand side by side as in a picture. They
form no single whole to be embraced at one glance, in which case
alone there would have been danger of having the eye more attracted
by the Laocoon than by the burning city. The two descriptions
succeed each other, and I fail to see how the deepest emotion
produced by the first could prejudice the one that follows. Any want
of effect in the second must be owing to its inherent want of pathos.
Still less reason would the poet have had for altering the serpents’
coils. In the marble they occupy the hands and encumber the feet, an
arrangement not less impressive to the imagination than satisfactory
to the eye. The picture is so distinct and clear that words can scarcely
make it plainer than natural signs.
Micat alter et ipsum
Laocoonta petit, totumque infraque supraque
Implicat et rabido tandem ferit ilia morsu.

· · · · ·

At serpens lapsu crebro redeunte subintrat


Lubricus, intortoque ligat genua infima nodo.

These lines are by Sadolet. They would doubtless have come with
greater picturesqueness from Virgil, had his fancy been fired by the
visible model. Under those circumstances he would certainly have
written better lines than those we now have of him.
Bis medium amplexi, bis collo squamea circum
Terga dati, superant capite et cervicibus altis.

These details satisfy the imagination, it is true; but not if we dwell


upon them and try to bring them distinctly before us. We must look
now at the serpents, and now at Laocoon. The moment we try to
combine them into one picture, the grouping begins to displease, and
appear in the highest degree unpicturesque.
But these deviations from his supposed model, even if not
unfortunate, were entirely arbitrary. Imitation is intended to produce
likeness, but how can likeness result from needless changes? Such
changes rather show that the intention was not to produce likeness,
consequently that there has been no imitation.
Perhaps not of the whole, some may urge, but of certain parts.
Good; but what are the parts so exactly corresponding in the marble
and in the poem, that the poet might seem to have borrowed them
from the sculptor? The father, the children, and the serpents, both
poet and sculptor received from history. Except what is traditional in
both, they agree in nothing but the single circumstance that father
and sons are bound by the serpents’ coils into a single knot. But this
arose from the new version, according to which father and sons were
involved in a common destruction,—a version, as already shown, to
be attributed rather to Virgil, since the Greek traditions tell the story
differently. If, then, there should have been any imitation here, it is
more likely to have been on the side of the artist than of the poet. In
all other respects their representations differ, but in such a way that
the deviations, if made by the artist, are perfectly consistent with an
intention to copy the poet, being such as the sphere and limitations
of his art would impose on him. They are, on the contrary, so many
arguments against the supposed imitation of the sculptor by the
poet. Those who, in the face of these objections, still maintain this
supposition, can only mean that the group is older than the poem.
VII.

When we speak of an artist as imitating a poet or a poet an artist,


we may mean one of two things,—either that one makes the work of
the other his actual model, or that the same original is before them
both, and one borrows from the other the manner of copying it.
When Virgil describes the shield of Æneas, his imitation of the
artist who made the shield is of the former kind. The work of art, not
what it represents, is his model. Even if he describe the devices upon
it they are described as part of the shield, not as independently
existing objects. Had Virgil, on the other hand, copied the group of
the Laocoon, this would have been an imitation of the second kind.
He would then have been copying, not the actual group, but what the
group represents, and would have borrowed from the marble only
the details of his copy.
In imitations of the first kind the poet is an originator, in those of
the second a copyist. The first is part of the universal imitation which
constitutes the very essence of his art, and his work is that of a
genius, whether his model be nature or the product of other arts. The
second degrades him utterly. Instead of the thing itself, he imitates
its imitations, and gives us a lifeless reflection of another’s genius for
original touches of his own.
In the by no means rare cases where poet and artist must study
their common original from the same point of view, their copies
cannot but coincide in many respects, although there may have been
no manner of imitation or emulation between them. These
coincidences among contemporaneous artists and poets may lead to
mutual illustrations of things no longer present to us. But to try to
help out these illustrations by tracing design where was only chance,
and especially by attributing to the poet at every detail a reference to
this statue or that picture, is doing him very doubtful service. Nor is
the reader a gainer by a process which renders the beautiful passages
perfectly intelligible, no doubt, but at the sacrifice of all their life.
This is the design and the mistake of a famous English work by the
Rev. Mr. Spence, entitled, “Polymetis; or, An inquiry concerning the
agreement between the works of the Roman poets and the remains of
the ancient artists, being an attempt to illustrate them mutually from
one another.”[47] Spence has brought to his work great classical
learning and a thorough knowledge of the surviving works of ancient
art. His design of using these as means to explain the Roman poets,
and making the poets in turn throw light on works of art hitherto
imperfectly understood, has been in many instances happily
accomplished. But I nevertheless maintain that to every reader of
taste his book must be intolerable.
When Valerius Flaccus describes the winged thunderbolts on the
shields of the Roman soldiers,—
Nec primus radios, miles Romane, corusci
Fulminis et rutilas scutis diffuderis alas,

the description is naturally made more intelligible to me by seeing


the representation of such a shield on an ancient monument.[48] It is
possible that the old armorers represented Mars upon helmets and
shields in the same hovering attitude that Addison thought he saw
him in with Rhea on an ancient coin,[49] and that Juvenal had such a
helmet or shield in mind in that allusion of his which, till Addison,
had been a puzzle to all commentators.
The passage in Ovid where the wearied Cephalus invokes Aura, the
cooling zephyr,—
“Aura ... venias ...
Meque juves, intresque sinus, gratissima, nostros,”

and his Procris takes this Aura for the name of a rival,—this passage,
I confess, seems to me more natural when I see that the ancients in
their works of art personified the gentle breezes, and, under the
name Auræ, worshipped certain female sylphs.[50]
I acknowledge that when Juvenal compares an idle patrician to a
Hermes-column, we should hardly perceive the point of the
comparison unless we had seen such a column and knew it to be a
poorly cut pillar, bearing the head, or at most the trunk, of the god,
and, owing to the want of hands and feet, suggesting the idea of
inactivity.[51]
Illustrations of this kind are not to be despised, though neither
always necessary nor always conclusive. Either the poet regarded the
work of art not as a copy but as an independent original, or both
artist and poet were embodying certain accepted ideas. Their
representations would necessarily have many points of resemblance,
which serve as so many proofs of the universality of the ideas.
But when Tibullus describes Apollo as he appeared to him in a
dream,—the fairest of youths, his temples wreathed with the chaste
laurel, Syrian odors breathing from his golden hair that falls in
ripples over his long neck, his whole body as pink and white as the
cheek of the bride when led to her bridegroom,—why need these
traits have been borrowed from famous old pictures? Echion’s “nova
nupta verecundia notabilis” may have been in Rome and been copied
thousands of times: did that prove virgin modesty itself to have
vanished from the world? Since the painter saw it, was no poet to see
it more save in the painter’s imitation?[52] Or when another poet
speaks of Vulcan as wearied and his face reddened by the forge, did
he need a picture to teach him that labor wearies and heat reddens?
[53]
Or when Lucretius describes the alternations of the seasons and
brings them before us in the order of nature, with their whole train of
effects on earth and air, was Lucretius the creature of a day? had he
lived through no entire year and seen its changes, that he must needs
have taken his description from a procession of statues representing
the seasons? Did he need to learn from statues the old poetic device
of making actual beings out of such abstractions?[54] Or Virgil’s
“pontem indignatus Araxes,” that admirable poetic picture of a river
overflowing its banks and tearing down the bridge that spans it,—do
we not destroy all its beauty by making it simply a reference to some
work of art, wherein the river god was represented as actually
demolishing a bridge?[55] What do we want of such illustrations
which banish the poet from his own clearest lines to give us in his
place the reflection of some artist’s fancy?
I regret that this tasteless conceit of substituting for the creations
of the poet’s own imagination a familiarity with those of others
should have rendered a book, so useful as the Polymetis might have
been made, as offensive as the feeblest commentaries of the
shallowest quibblers, and far more derogatory to the classic authors.
Still more do I regret that Addison should in this respect have been
the predecessor of Spence, and, in his praiseworthy desire to make
the old works of art serve as interpreters, have failed to discriminate
between those cases where imitation of the artist would be becoming
in the poet, and those where it would be degrading to him.[56]
VIII.

Spence has the strangest notions of the resemblance between


painting and poetry. He believes the two arts to have been so closely
connected among the ancients that they always went hand in hand,
the poet never losing sight of the painter, nor the painter of the poet.
That poetry has the wider sphere, that beauties are within her reach
which painting can never attain, that she may often see reason to
prefer unpicturesque beauties to picturesque ones,—these things
seem never to have occurred to him. The slightest difference,
therefore, between the old poets and artists throws him into an
embarrassment from which it taxes all his ingenuity to escape.
The poets generally gave Bacchus horns. Spence is therefore
surprised that we seldom see these appendages on his statues.[57] He
suggests one reason and another; now the ignorance of the
antiquarians, and again “the smallness of the horns themselves,
which were very likely to be hid under the crown of grapes or ivy
which is almost a constant ornament of the head of Bacchus.” He
goes all round the true cause without ever suspecting it. The horns of
Bacchus were not a natural growth like those of fauns and satyrs.
They were ornaments which he could assume or lay aside at
pleasure.
Tibi, cum sine cornibus adstas,
Virgineum caput est, ...

says Ovid in his solemn invocation to Bacchus.[58] He could therefore


show himself without horns, and did, in fact, thus show himself when
he wished to appear in his virgin beauty. In this form artists would
choose to represent him, and necessarily omitted all disagreeable
accompaniments. Horns fastened to the diadem, as we see them on a
head in the royal museum in Berlin,[59] would have been a
cumbersome appendage, as would also the diadem itself, concealing
the beautiful brow. For this reason the diadem appears as rarely as
the horns on the statues of Bacchus, although, as its inventor, he is
often crowned with it by the poets. In poetry both horns and diadem
served as subtle allusions to the deeds and character of the god: in a
picture or statue they would have stood in the way of greater
beauties. If Bacchus, as I believe, received the name of Biformis,
Δίμορφος, from having an aspect of beauty as well as of terror, the
artists would naturally have chosen the shape best adapted to the
object of their art.
In the Roman poets Minerva and Juno often hurl the thunderbolt.
Why are they not so represented in art? asks Spence.[60] He answers,
“This power was the privilege of these two goddesses, the reason of
which was, perhaps, first learnt in the Samothracian mysteries. But
since, among the ancient Romans, artists were considered as of
inferior rank, and therefore rarely initiated into them, they would
doubtless know nothing of them; and what they knew not of they
clearly could not represent.” I should like to ask Spence whether
these common people were working independently, or under the
orders of superiors who might be initiated into the mysteries;
whether the artists occupied such a degraded position among the
Greeks; whether the Roman artists were not for the most part Greeks
by birth; and so on.
Statius and Valerius Flaccus describe an angry Venus with such
terrible features that we should take her at the moment for a fury
rather than for the goddess of love. Spence searches in vain for such
a Venus among the works of ancient art. What is his conclusion?
That more is allowed to the poet than to the sculptor and painter?
That should have been his inference. But he has once for all
established as a general rule that “scarce any thing can be good in a
poetical description which would appear absurd if represented in a
statue or picture.”[61] Consequently the poets must be wrong. “Statius
and Valerius Flaccus belong to an age when Roman poetry was
already in its decline. In this very passage they display their bad
judgment and corrupted taste. Among the poets of a better age such
a repudiation of the laws of artistic expression will never be
found.”[62]
Such criticism shows small power of discrimination. I do not
propose to undertake the defence of either Statius or Valerius, but
will simply make a general remark. The gods and other spiritual
beings represented by the artist are not precisely the same as those
introduced by the poet. To the artist they are personified abstractions
which must always be characterized in the same way, or we fail to
recognize them. In poetry, on the contrary, they are real beings,
acting and working, and possessing, besides their general character,
qualities and passions which may upon occasion take precedence.
Venus is to the sculptor simply love. He must therefore endow her
with all the modest beauty, all the tender charms, which, as
delighting us in the beloved object, go to make up our abstract idea
of love. The least departure from this ideal prevents our recognizing
her image. Beauty distinguished more by majesty than modesty is no
longer Venus but Juno. Charms commanding and manly rather than
tender, give us, instead of a Venus, a Minerva. A Venus all wrath, a
Venus urged by revenge and rage, is to the sculptor a contradiction in
terms. For love, as love, never is angry, never avenges itself. To the
poet, Venus is love also, but she is the goddess of love, who has her
own individuality outside of this one characteristic, and can therefore
be actuated by aversion as well as affection. What wonder, then, that
in poetry she blazes into anger and rage, especially under the
provocation of insulted love?
The artist, indeed, like the poet, may, in works composed of
several figures, introduce Venus or any other deity, not simply by her
one characteristic, but as a living, acting being. But the actions, if not
the direct results of her character, must not be at variance with it.
Venus delivering to her son the armor of the gods is a subject equally
suitable to artist and poet. For here she can be endowed with all the
grace and beauty befitting the goddess of love. Such treatment will be
of advantage as helping us the more easily to recognize her. But
when Venus, intent on revenging herself on her contemners, the men
of Lemnos, wild, in colossal shape, with cheeks inflamed and
dishevelled hair, seizes the torch, and, wrapping a black robe about
her, flies downward on the storm-cloud,—that is no moment for the
painter, because he has no means of making us recognize her. The
poet alone has the privilege of availing himself of it. He can unite it
so closely with some other moment when the goddess is the true
Venus, that we do not in the fury forget the goddess of love. Flaccus
does this,—
Neque enim alma videri
Jam tumet; aut tereti crinem subnectitur auro,
Sidereos diffusa sinus. Eadem effera et ingens
Et maculis suffecta genas; pinumque sonantem
Virginibus Stygiis, nigramque simillima pallam.[63]

And Statius also,—


Illa Paphon veterem centumque altaria linquens,
Nec vultu nec crine prior, solvisse jugalem
Ceston, et Idalias procul ablegasse volucres
Fertur. Erant certe, media qui noctis in umbra
Divam, alios ignes majoraque tela gerentem,
Tartarias inter thalamis volitasse sorores
Vulgarent: utque implicitis arcana domorum
Anguibus, et sæva formidine cuncta replerit
Limina.[64]

Or, we may say, the poet alone possesses the art of so combining
negative with positive traits as to unite two appearances in one. No
longer now the tender Venus, her hair no more confined with golden
clasps, no azure draperies floating about her, without her girdle,
armed with other flames and larger arrows, the goddess hastes
downward, attended by furies of like aspect with herself. Must the
poet abstain from the use of this device because artists are debarred
from it? If painting claim to be the sister of poetry, let the younger at
least not be jealous of the elder, nor seek to deprive her of ornaments
unbecoming to herself.
IX.

When we compare poet and painter in particular instances, we


should be careful to inquire whether both have had entire freedom,
and been allowed to labor for the highest results of their art without
the exercise of any constraint from without.
Religion often exercised such constraint upon the old artists. A
work, devotional in character, must often be less perfect than one
intended solely to produce pleasure. Superstition loaded the gods
with symbols which were not always reverenced in proportion to
their beauty.
In the temple of Bacchus at Lemnos, from which the pious
Hypsipyle rescued her father under the guise of the deity,[65] the god
was represented horned. So he doubtless appeared in all his temples,
the horns being symbols typical of his nature and functions. The
unfettered artist, whose Bacchus was not designed for a temple,
omitted the symbol. If, among the statues of the god that remain to
us, we find none with horns,[66] that circumstance perhaps proves
that none of them were sacred statues, representing the god in the
shape under which he was worshipped. We should naturally expect,
too, that against such the fury of the pious iconoclasts in the first
centuries of Christianity would have been especially directed. Only
here and there a work of art was spared, because it had never been
desecrated by being made an object of worship.
But since, among the antiques that have been unburied, there are
specimens of both kinds, we should discriminate and call only those
works of art which are the handiwork of the artist, purely as artist,
those where he has been able to make beauty his first and last object.
All the rest, all that show an evident religious tendency, are unworthy
to be called works of art. In them Art was not working for her own
sake, but was simply the tool of Religion, having symbolic
representations forced upon her with more regard to their
significance than their beauty. By this I do not mean to deny that
religion often sacrificed meaning to beauty, or so far ceased to
emphasize it, out of regard for art and the finer taste of the age, that
beauty seemed to have been the sole end in view.
If we make no such distinction, there will be perpetual strife
between connoisseurs and antiquarians from their failure to
understand each other. When the connoisseur maintains, according
to his conception of the end and aim of art, that certain things never
could have been made by one of the old artists, meaning never by
one working as artist from his own impulse, the antiquarian will
understand him to say that they could never have been fashioned by
the artist, as workman, under the influence of religion or any other
power outside the domain of art. He will therefore think to confute
his antagonist by showing some figure which the connoisseur,
without hesitation, but to the great vexation of the learned world,
will condemn back to the rubbish from which it had been dug.[67]
But there is danger, on the other hand, of exaggerating the
influence of religion on art. Spence furnishes a remarkable instance
of this. He found in Ovid that Vesta was not worshipped in her
temple under any human image, and he thence drew the conclusion
that there had never been any statues of the goddess. What had
passed for such must be statues, not of Vesta, but of a vestal virgin.
[68]
An extraordinary conclusion! Because the goddess was
worshipped in one of her temples under the symbol of fire, did artists
therefore lose all right to personify after their fashion a being to
whom the poets give distinct personality, making her the daughter of
Saturn and Ops, bringing her into danger of falling under the ill
treatment of Priapus, and narrating yet other things in regard to her?
For Spence commits the further error of applying to all the temples
of Vesta and to her worship generally what Ovid says only of a
certain temple at Rome.[69] She was not everywhere worshipped as in
this temple at Rome. Until Numa erected this particular sanctuary,
she was not so worshipped even in Italy. Numa allowed no deity to
be represented in the shape of man or beast. In this prohibition of all
personal representations of Vesta consisted, doubtless, the
reformation which he introduced into her rites. Ovid himself tells us
that, before the time of Numa, there were statues of Vesta in her
temple, which, when her priestess Sylvia became a mother, covered
their eyes with their virgin hands.[70] Yet further proof that in the
temples of the goddess outside the city, in the Roman provinces, her
worship was not conducted in the manner prescribed by Numa, is
furnished by various old inscriptions, where mention is made of a
priest of Vesta (Pontificis Vestæ).[71] At Corinth, again, was a temple
of Vesta without statues, having only an altar whereon sacrifices
were offered to the goddess.[72] But did the Greeks, therefore, have no
statues of Vesta? There was one at Athens in the Prytaneum, next to
the statue of Peace.[73] The people of Iasos boasted of having one in
the open air, upon which snow and rain never fell.[74] Pliny mentions
one in a sitting posture, from the chisel of Scopas, in the Servilian
gardens at Rome, in his day.[75] Granting that it is difficult for us now
to distinguish between a vestal virgin and the goddess herself, does
that prove that the ancients were not able or did not care to make the
distinction? Certain attributes point evidently more to one than the
other. The sceptre, the torch, and the palladium would seem to
belong exclusively to the goddess. The tympanum, attributed to her
by Codinus, belongs to her, perhaps, only as the Earth. Or perhaps
Codinus himself did not know exactly what it was he saw.[76]
X.

Spence’s surprise is again aroused in a way that shows how little he


has reflected on the limits of poetry and painting.
“As to the muses in general,” he says, “it is remarkable that the
poets say but little of them in a descriptive way; much less than
might indeed be expected for deities to whom they were so
particularly obliged.”[77]
What is this but expressing surprise that the poets, when they
speak of the muses, do not use the dumb language of the painter? In
poetry, Urania is the muse of astronomy. Her name and her
employment reveal her office. In art she can be recognized only by
the wand with which she points to a globe of the heavens. The wand,
the globe, and the attitude are the letters with which the artist spells
out for us the name Urania. But when the poet wants to say that
Urania had long read her death in the stars,—
Ipsa diu positis lethum prædixerat astris
Urania.[78]

Why should he add, out of regard to the artist,—Urania, wand in


hand, with the heavenly globe before her? Would that not be as if a
man, with the power and privilege of speech, were to employ the
signs which the mutes in a Turkish seraglio had invented to supply
the want of a voice?
Spence expresses the same surprise in regard to the moral beings,
or those divinities who, among the ancients, presided over the
virtues and undertook the guidance of human life.[79] “It is
observable,” he says, “that the Roman poets say less of the best of
these moral beings than might be expected. The artists are much
fuller on this head; and one who would know how they were each set
off must go to the medals of the Roman emperors. The poets, in fact,
speak of them very often as persons; but of their attributes, their
dress, and the rest of their figure they generally say but little.”
When a poet personifies abstractions he sufficiently indicates their
character by their name and employment.
These means are wanting to the artist, who must therefore give to
his personified abstractions certain symbols by which they may be
recognized. These symbols, because they are something else and
mean something else, constitute them allegorical figures.
A female figure holding a bridle in her hand, another leaning
against a column, are allegorical beings. But in poetry Temperance
and Constancy are not allegorical beings, but personified
abstractions.
Necessity invented these symbols for the artist, who could not
otherwise indicate the significance of this or that figure. But why
should the poet, for whom no such necessity exists, be obliged to
accept the conditions imposed upon the artist?
What excites Spence’s surprise should, in fact, be prescribed as a
law to all poets. They should not regard the limitations of painting as
beauties in their own art, nor consider the expedients which painting
has invented in order to keep pace with poetry, as graces which they
have any reason to envy her. By the use of symbols the artist exalts a
mere figure into a being of a higher order. Should the poet employ
the same artistic machinery he would convert a superior being into a
doll.
Conformity to this rule was as persistently observed by the
ancients as its studious violation is by the viciousness of modern
poets. All their imaginary beings go masked, and the writers who
have most skill in this masquerade generally understand least the
real object of their work, which is to let their personages act, and by
their actions reveal their character.
Among the attributes by which the artist individualizes his
abstractions, there is one class, however, better adapted to the poet
than those we have been considering, and more worthy of his use. I
refer to such as are not strictly allegorical, but may be regarded as
instruments which the beings bearing them would or could use,
should they ever come to act as real persons. The bridle in the hand
of Temperance, the pillar which supports Constancy are purely
allegorical, and cannot therefore be used by the poet. The scales in
the hand of Justice are less so, because the right use of the scales is
one of the duties of Justice. The lyre or flute in the hand of a muse,
the lance in the hand of Mars, hammer and tongs in the hands of
Vulcan, are not symbols at all, but simply instruments without which
none of the actions characteristic of these beings could be performed.
To this class belong the attributes sometimes woven by the old poets
into their descriptions, and which, in distinction from those that are
allegorical, I would call the poetical. These signify the thing itself,
while the others denote only some thing similar.[80]
XI.

Count Caylus also seems to require that the poet should deck out
the creatures of his imagination with allegorical attributes.[81] The
Count understood painting better than poetry.
But other points more worthy of remark have struck me in the
same work of his, some of the most important of which I shall
mention here for closer consideration.
The artist, in the Count’s opinion, should make himself better
acquainted with Homer, that greatest of all word painters,—that
second nature, in fact. He calls attention to the rich and fresh
material furnished by the narrative of the great Greek, and assures
the painter that the more closely he follows the poet in every detail,
the nearer his work will approach to perfection.
This is confounding the two kinds of imitation mentioned above.
The painter is not only to copy the same thing that the poet has
copied, but he is to copy it with the same touches. He is to use the
poet not only as narrator, but as poet.
But why is not this second kind of imitation, which we have found
to be degrading to the poet, equally so to the artist? If there had
existed previous to Homer such a series of pictures as he suggests to
Count Caylus, and we knew that the poet had composed his work
from them, would he not lose greatly in our estimation? Why should
we not in like manner cease to admire the artist who should do no
more than translate the words of the poet into form and color?
The reason I suppose to be this. In art the difficulty appears to lie
more in the execution than in the invention, while with poetry the
contrary is the case. There the execution seems easy in comparison
with the invention. Had Virgil copied the twining of the serpents
about Laocoon and his sons from the marble, then his description
would lose its chief merit; for what we consider the more difficult
part had been done for him. The first conception of this grouping in
the imagination is a far greater achievement than the expression of it
in words. But if the sculptor have borrowed the grouping from the
poet, we still consider him deserving of great praise, although he
have not the merit of the first conception. For to give expression in
marble is incalculably more difficult than to give it in words. We
weigh invention and execution in opposite scales, and are inclined to
require from the master as much less of one as he has given us more
of the other.
There are even cases where the artist deserves more credit for
copying Nature through the medium of the poet’s imitation than
directly from herself. The painter who makes a beautiful landscape
from the description of a Thomson, does more than one who takes
his picture at first hand from nature. The latter sees his model before
him; the former must, by an effort of imagination, think he sees it.
One makes a beautiful picture from vivid, sensible impressions, the
other from the feeble, uncertain representations of arbitrary signs.
From this natural readiness to excuse the artist from the merit of
invention, has arisen on his part an equally natural indifference to it.
Perceiving that invention could never be his strong point, but that his
fame must rest chiefly on execution, he ceased to care whether his
theme were new or old, whether it had been used once or a hundred
times, belonged to himself or another. He kept within the narrow
range of a few subjects, grown familiar to himself and the public, and
directed all his invention to the introducing of some change in the
treatment, some new combination of the old objects. That is actually
the meaning attached to the word “invention” in the old text-books
on painting. For although they divide it into the artistic and the
poetic, yet even the poetic does not extend to the originating of a
subject, but solely to the arrangement or expression.[82] It is
invention, not of the whole, but of the individual parts and their
connection with one another; invention of that inferior kind which
Horace recommended to his tragic poet:
Tuque
Rectius Iliacum carmen deducis in actus,
Quam si proferres ignota indictaque primus.[83]
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!

ebookmass.com

You might also like