view doc/misc/html/oldclasslib/array.html @ 2:4b08ee1ecb99

Adjust install notes to clarify that Wine applies only to the Windows build. (Thanks to Perry Metzger for test-driving.)
author David A. Holland
date Sun, 26 Apr 2009 17:58:26 -0400
parents 13d2b8934445
children
line wrap: on
line source

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Array Storage Class Definition</TITLE>
</HEAD>


<BODY BGCOLOR="#ffffff" BACKGROUND="tilbl6h.gif"
 TEXT="#000000" LINK="#0033CC"
 VLINK="#CC0033" ALINK="#CC0099">

<P>
<IMG ALIGN="right" SRC="../images/agrsl6c.gif" ALT="AnaGram"
         WIDTH=124 HEIGHT=30 >
<BR CLEAR="all">
Back to :
<A HREF="../index.html">Index</A> |
<A HREF="index.html">Class libraries for examples</A>
<P>

<IMG ALIGN="bottom" SRC="../images/rbline6j.gif" ALT="----------------------"
        WIDTH=1010 HEIGHT=2  >
<P>

<H1>Array Storage Class Definition</H1>
<IMG ALIGN="bottom" SRC="../images/rbline6j.gif" ALT="----------------------"
        WIDTH=1010 HEIGHT=2  >
<P>
<BR>
<H2>Introduction</H2>
<P>

          <CODE>array&lt;class T&gt; </CODE>
          is a template class that provides for storage
          of arrays of any type. It takes care of allocating storage
          and releasing it on function exit. It also checks all array
          accesses for valid index values, providing protection against
          out of bounds references.
<P>
<BR>

<H2>     Constructors </H2>

          There are two constructors:
<PRE>
            array&lt;class T&gt;(unsigned n);
            array&lt;class T&gt;(T *init_array, unsigned n);
</PRE>
          The first constructor simply allocates an array of n elements
          of type T and clears the array to zero.
<P>
          The second constructor allocates an array of n elements of
          type T and copies the contents of init_array to it.
<P>
          Examples:
<PRE>
            array<int> integers(300);
            array<char> str("Hello, world", 13);
</PRE>
<P>
<BR>

<H2>     Data Access </H2>

          Two overloaded operators, the cast operator <CODE> (T *) </CODE>
          and the subscript operator <CODE> []</CODE>, provide access to the
          contents of the array. The cast operator provides a pointer to the
          data in the array. The subscript operator provides a reference to a
          particular element, which can be used either to read or to
          write the element. Note that the use of cast operators is
          often implicit rather than explicit.
<P>
          For example, using the above declarations, one may write:
<PRE>
            int k = integers[20];
            int *p = integers;        // Implicit use of cast operator
            char *sp = str;           // Implicit use of cast operator
            char c = str[5];
            str[6] = '!';
</PRE>
          The effect of these definitions is that for almost all
          purposes you can use the array name exactly as though it were
          a pointer to your data.
<P>
<BR>

<H2>     Size of the Array </H2>

          To find the length of a local array, use size():
<PRE>
            int n = size(integers);
</PRE>
<P>
<BR>


<IMG ALIGN="bottom" SRC="../images/rbline6j.gif" ALT="----------------------"
      WIDTH=1010 HEIGHT=2 >
<P>
<IMG ALIGN="right" SRC="../images/pslrb6d.gif" ALT="Parsifal Software"
                WIDTH=181 HEIGHT=25>
<BR CLEAR="right">

<P>
Back to :
<A HREF="../index.html">Index</A> |
<A HREF="index.html">Class libraries for examples</A>
<P>

<ADDRESS><FONT SIZE="-1">
                  AnaGram parser generator - examples<BR>
                  Array Storage Class Definition<BR>
                  Copyright &copy; 1993-1999, Parsifal Software. <BR>
                  All Rights Reserved.<BR>
</FONT></ADDRESS>

</BODY>
</HTML>