Original Post
hi, i've tried debugging this to the best of my abilities and i've come up with squat. perhaps one of you experts can shed some light on what's happening in the following code.
basically, i have a composite class Foo which contains a dynamic array of types Bar.
i'm not sure whether this makes a difference or not but type Bar contains data members of type string. based on the fact that string defines pretty much every overload and enough memory management to hold it's own, i'm under the impression that its inclusion in this example is irrelevant, however...
anyway, everything works ok up to the point where i'm trying to re-point Foo's array pointer to the newly created array. here's the code...
..:: mirirom ::..
[edited by - mirirom on November 24, 2003 12:40:56 AM]
class Bar{
private:
string strCharName; int life;
public:
//...get n' sets, et al...
};
class Foo{
private:
Bar *characters; int count, currentSize;
public:
Bar();
~Bar();
appendChar(const &string, int);
resizeArray(Bar*);
};
Foo::Bar(){
count = 0; currentSize = 2;
characters = new Bar[currentSize];
}
Foo::~Bar(){
delete[] characters;
)
Foo::appendChar(const &string s, int i){
if(count == currentSize)
resizeArray(characters);
characters[count++].set(s, i);
}
Foo::resizeArray(Bar* c){
currentSize+=2;
Bar* temp = new Bar[currentSize]; //check for fail, blah blah
for(int i=0; i < count; i++){
temp[i] = c[i];
}
delete[] c;
c = temp; //error is thrown here...at times
}
am i missing something or...? any help, advice, suggestion is greatly appreciated. thanks in advance!