home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
1991
/
10
/
string
/
striarr.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-30
|
529b
|
25 lines
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <string.hpp>
char &String::operator[](int i)
{
if (!rp || i < 0 || i >= length()) {
errno = ERANGE;
return dummy;
}
if (rp->refs > 1) {
srep *p = new(length()) srep(length());
if (!p) {
errno = ENOMEM;
return dummy;
}
memmove(p->body,body(),length());
if (--rp->refs < 1)
delete rp;
rp = p;
}
return *(rp->body+i);
}