April 25th, 2013, 04:48 PM
Re: problems on resize an array:(
int ReDim(void *ag,size_t i)
(typeid(ag).name()*) realloc (ag, i * sizeof(typeid(ag).name()));
Whatever you thought this code was going to accomplish, it doesn't!
realloc returns a pointer to the new memory and needs to be assigned. ag is a pointer to void passed by value so that even if ag is assigned to the return value of realloc, the new value won't get returned to the caller. ag either needs to be passed as a pointer to a pointer or (better) as a reference to a pointer. typeid(..).name() returns a const char * string so sizeof will always give the wrong value (and in any case doesn't provide what you think it provides!).
As Paul already stated, why are you trying to incorrectly use the 'c' method of memory allocation when there are so much better ways of doing this in c++???? If you insist on using malloc/realloc/free then you need a good understanding of how this all hangs together and how pointers work and how to pass values back from functions etc etc etc.
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Click Here to Expand Forum to Full Width