delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/05/01:32:49

Message-ID: <20000605053232.34281.qmail@hotmail.com>
X-Originating-IP: [208.160.246.197]
From: "Nimrod Abing" <n_abing AT hotmail DOT com>
To: djgpp AT delorie DOT com
Subject: Re: Vectors and the libg++
Date: Mon, 05 Jun 2000 13:32:32 PHT
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

>From: "Robert Boles" <zingen AT prodigy DOT net>
>Reply-To: djgpp AT delorie DOT com
>To: djgpp AT delorie DOT com
>Subject: Vectors and the libg++
>Date: Sat, 3 Jun 2000 20:18:45 -0400
>
>Hello,
>does anyone know where to get examples of how to use the libgpp. I have
>found the doccumantation inder the "Info", but that doesnt tell me how to
>use it. I have gotten the string class to work, but I would like to use the
>vector class, and I can't figure out how to make a dynamic array of classes
>using vector,
>
>
>
If you are refering to the C++ standard library and STL or Standard
Template Library, The C++ book written by Bjarne Stroustrup himself
has many examples on using the STL and C++ standard library. Go look
for it... Be sure the get the latest edition. The Gnu C++ (libgpp.a)
library is no longer maintained, so new C++ code should use STL.

But if you're in a hurry... I assume you have a thorough understanding
of the C++ template mechanism.

To use the STL vector template container class:

1. Define the classes that you wish to store in the vector. It must
have the following:

    a. Default constructor
    b. Copy constructor and assignment operator
    c. overload of '==' and '<'

Note that these three are requirements and that *all* classes must have
them in order for them to be stored in an STL container. Or in the
SGI STL Documentation terms:

    In order for a class to be stored in an STL container, it must be
    DefaultConstructible, Assignable, EqualityComparable,
    and LessThanComparable.

2. Once you've done the things above, declare a container object or
a `typedef':

    vector<my_new_class> my_new_classes(num_elements);

                        -- or --

    typedef vector<my_new_class> my_new_class_vect;

Have fun...


----------------
_nimrod_a_abing_


------------------------------------------
Homepage: http://www.geocities.com/n_abing

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019