Having trouble implementing my own reserve function. ( have to do it for an assignment)
Here is what i have so far but it doesn't appear to work.
.h prototype
void reserve(size_type n);
constructor for our string
mystring::mystring(const char * s) {
len = strlen(s);
buf_size = len + 1;
ptr_buffer = new char[buf_size];
strcpy(ptr_buffer, s);
}
reserve function:
void mystring::reserve(size_type n){
if(n > buf_size){
char *hold = ptr_buffer;
delete ptr_buffer;
ptr_buffer = new char[n+1];
ptr_buffer = hold;
delete hold;
buf_size = n+1;
}
}
n is size_type unsigned int
The .h was supplied and we cannot change it.