www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/12/25/18:06:45

From: "Traveler" <traveler AT netti DOT fi>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Templates
Date: Tue, 26 Dec 2000 01:08:38 +0200
Organization: SAUNALAHDEN asiakas
Lines: 32
Message-ID: <928j3b$bh0$1@tron.sci.fi>
References: <Q7N16.4022$7f3 DOT 268692 AT bgtnsc07-news DOT ops DOT worldnet DOT att DOT net>
NNTP-Posting-Host: dxcv.tdyn.saunalahti.fi
X-Trace: tron.sci.fi 977784747 11808 195.197.80.95 (25 Dec 2000 22:52:27 GMT)
X-Complaints-To: newsmaster AT saunalahti DOT fi
NNTP-Posting-Date: 25 Dec 2000 22:52:27 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Try this: (a little compact version but I hope that you do not mind.)
Besides, the less you have to type the less there are errors in your code

(New array.h)
template <class T>
class array
{
    T*    arr;
    int    size;
public:
    int    length() const {return size;}
    array(int sizel)
    {
        if(size < 0)
            cerr << "IllegalArraySize" << size;
        arr = new T[this -> size = size];
    }
    virtual ~array() {delete [] arr;}
    T&    operator[}(int index)
    {
            if(index < 0 || index > size)
                cerr << "ArrayOutOfBoundsException:" << index;
            return    arr[index];
    }
};

traveler AT netti DOT fi
"Traveler 2000AD"



- Raw text -


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