Skip to main content
Contents
Dark Mode Prev Up Next Scratch ActiveCode Profile
\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 10.3 Copying vectors
There is one more constructor for
vector
s, which is called a copy constructor because it takes one
vector
as an argument and creates a new vector that is the same size, with the same elements.
vector<int> countCopy(count);
Although this syntax is legal, it is almost never used for
vector
s because there is a better alternative:
vector<int> countCopy = count;
The
=
operator works on
vector
s in pretty much the way you would expect.
Listing 10.3.1. Take a look at this active code, which uses the copy constructor.
Checkpoint 10.3.1 .
Multiple Response How would you make a copy of
vector<double> decimals
called
nums ?
vector<double> nums = decimals;
This is one way to make a copy.
vector<double> decimals = nums;
This makes a copy of nums called decimals.
vector<double> nums (decimals);
This is one way to make a copy.
vector<double> decimals (nums);
This makes a copy of nums called decimals.
Checkpoint 10.3.2 .
You have attempted
of
activities on this page.