View Single Post
Old 12-15-2004, 07:40 PM   #6 (permalink)
ergdork
Tilted
 
Quote:
Originally Posted by Rekna
Code:
Class DynamicArray
{
   public: 
         DynamicArray(int size);
         ~DynamicArray();
   private:
         char *A;
         int N;
 };

DynamicArray::DynamicArray(int size)
{
    N=size;
    A=new int[N];
}
DynamicArray::~DynamicArray()
{
    delete A;
}
I havn't compiled this or anything so there may be a few typos but you should get the basic idea.

Then just add what ever functionality you want.
The only small change to this implementation is that technically, it should be:
Code:
delete[] A;
Also - assuming you are willing to get into STL and use templates, I would recommend it. They have variable length strings, vectors, lists, iterators, etc. It does require a bit of understanding of the theory of C++ and object oriented programming, though.

A good reference:
http://www.sgi.com/tech/stl
ergdork is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47