Mercurial > ~dholland > hg > ag > index.cgi
comparison doc/misc/html/oldclasslib/array.html @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> | |
2 <HTML> | |
3 <HEAD> | |
4 <TITLE>Array Storage Class Definition</TITLE> | |
5 </HEAD> | |
6 | |
7 | |
8 <BODY BGCOLOR="#ffffff" BACKGROUND="tilbl6h.gif" | |
9 TEXT="#000000" LINK="#0033CC" | |
10 VLINK="#CC0033" ALINK="#CC0099"> | |
11 | |
12 <P> | |
13 <IMG ALIGN="right" SRC="../images/agrsl6c.gif" ALT="AnaGram" | |
14 WIDTH=124 HEIGHT=30 > | |
15 <BR CLEAR="all"> | |
16 Back to : | |
17 <A HREF="../index.html">Index</A> | | |
18 <A HREF="index.html">Class libraries for examples</A> | |
19 <P> | |
20 | |
21 <IMG ALIGN="bottom" SRC="../images/rbline6j.gif" ALT="----------------------" | |
22 WIDTH=1010 HEIGHT=2 > | |
23 <P> | |
24 | |
25 <H1>Array Storage Class Definition</H1> | |
26 <IMG ALIGN="bottom" SRC="../images/rbline6j.gif" ALT="----------------------" | |
27 WIDTH=1010 HEIGHT=2 > | |
28 <P> | |
29 <BR> | |
30 <H2>Introduction</H2> | |
31 <P> | |
32 | |
33 <CODE>array<class T> </CODE> | |
34 is a template class that provides for storage | |
35 of arrays of any type. It takes care of allocating storage | |
36 and releasing it on function exit. It also checks all array | |
37 accesses for valid index values, providing protection against | |
38 out of bounds references. | |
39 <P> | |
40 <BR> | |
41 | |
42 <H2> Constructors </H2> | |
43 | |
44 There are two constructors: | |
45 <PRE> | |
46 array<class T>(unsigned n); | |
47 array<class T>(T *init_array, unsigned n); | |
48 </PRE> | |
49 The first constructor simply allocates an array of n elements | |
50 of type T and clears the array to zero. | |
51 <P> | |
52 The second constructor allocates an array of n elements of | |
53 type T and copies the contents of init_array to it. | |
54 <P> | |
55 Examples: | |
56 <PRE> | |
57 array<int> integers(300); | |
58 array<char> str("Hello, world", 13); | |
59 </PRE> | |
60 <P> | |
61 <BR> | |
62 | |
63 <H2> Data Access </H2> | |
64 | |
65 Two overloaded operators, the cast operator <CODE> (T *) </CODE> | |
66 and the subscript operator <CODE> []</CODE>, provide access to the | |
67 contents of the array. The cast operator provides a pointer to the | |
68 data in the array. The subscript operator provides a reference to a | |
69 particular element, which can be used either to read or to | |
70 write the element. Note that the use of cast operators is | |
71 often implicit rather than explicit. | |
72 <P> | |
73 For example, using the above declarations, one may write: | |
74 <PRE> | |
75 int k = integers[20]; | |
76 int *p = integers; // Implicit use of cast operator | |
77 char *sp = str; // Implicit use of cast operator | |
78 char c = str[5]; | |
79 str[6] = '!'; | |
80 </PRE> | |
81 The effect of these definitions is that for almost all | |
82 purposes you can use the array name exactly as though it were | |
83 a pointer to your data. | |
84 <P> | |
85 <BR> | |
86 | |
87 <H2> Size of the Array </H2> | |
88 | |
89 To find the length of a local array, use size(): | |
90 <PRE> | |
91 int n = size(integers); | |
92 </PRE> | |
93 <P> | |
94 <BR> | |
95 | |
96 | |
97 <IMG ALIGN="bottom" SRC="../images/rbline6j.gif" ALT="----------------------" | |
98 WIDTH=1010 HEIGHT=2 > | |
99 <P> | |
100 <IMG ALIGN="right" SRC="../images/pslrb6d.gif" ALT="Parsifal Software" | |
101 WIDTH=181 HEIGHT=25> | |
102 <BR CLEAR="right"> | |
103 | |
104 <P> | |
105 Back to : | |
106 <A HREF="../index.html">Index</A> | | |
107 <A HREF="index.html">Class libraries for examples</A> | |
108 <P> | |
109 | |
110 <ADDRESS><FONT SIZE="-1"> | |
111 AnaGram parser generator - examples<BR> | |
112 Array Storage Class Definition<BR> | |
113 Copyright © 1993-1999, Parsifal Software. <BR> | |
114 All Rights Reserved.<BR> | |
115 </FONT></ADDRESS> | |
116 | |
117 </BODY> | |
118 </HTML> | |
119 |