File tree Expand file tree Collapse file tree 1 file changed +10
-20
lines changed Expand file tree Collapse file tree 1 file changed +10
-20
lines changed Original file line number Diff line number Diff line change 1362
1362
\term {template}
1363
1363
defines the layout and operations
1364
1364
for an unbounded set of related types.
1365
- \begin {example }
1366
- a single class template
1367
- \tcode {List}
1368
- might provide a common definition for
1369
- list of
1370
- \tcode {int},
1371
- list of
1372
- \tcode {float},
1373
- and list of pointers to
1374
- \tcode {Shape}s.
1375
- \end {example }
1376
1365
1366
+ \pnum
1377
1367
\begin {example }
1378
- An array class template might be declared like this:
1379
-
1368
+ A single class template
1369
+ \tcode {List}
1370
+ might provide an unbounded set of class definitions:
1371
+ one class \tcode {List<T>} for every type \tcode {T},
1372
+ each describing a linked list of elements of type \tcode {T}.
1373
+ Similarly, a class template \tcode {Array} describing a contiguous,
1374
+ dynamic array might be defined like this:
1380
1375
\begin {codeblock }
1381
1376
template<class T> class Array {
1382
1377
T* v;
1387
1382
T& elem(int i) { return v[i]; }
1388
1383
};
1389
1384
\end {codeblock }
1390
-
1391
- \pnum
1392
- The prefix
1393
- \tcode {template}
1394
- \tcode {<class}
1395
- \tcode {T>}
1385
+ The prefix \tcode {template<class T>}
1396
1386
specifies that a template is being declared and that a
1397
1387
\grammarterm {type-name}
1398
1388
\tcode {T}
1399
- will be used in the declaration.
1389
+ may be used in the declaration.
1400
1390
In other words,
1401
1391
\tcode {Array}
1402
1392
is a parameterized type with
You can’t perform that action at this time.
0 commit comments