There is one thing you need to realize:
When you do something incorrect when it comes to memory handling, just because the program "works" doesn't mean the program is correct. In C (or C++), if you make a mistake, there may be no indication that something is wrong, until you run the program on another computer, or the program may run some time and crash another time, etc.
That's why your attempt at trying to manage your own memory is flawed. I have never seen any code like this to allocate memory, and I've been doing C and C++ for 25 years now:
Code:
int ReDim(void *ag,size_t i)
{
(typeid(ag).name()*) realloc (ag, i * sizeof(typeid(ag).name()));
return 0;
}
Now, if I've never seen anything like this before from a beginner, then you know something just isn't right.
First, there is no such thing as
typeid in the 'C' language. So why are you using it?
Second, even if you were to do something like this in C++, you would use a template:
Code:
template <typename T>
T* ReDim(void *ag,size_t i)
{
return (T*) realloc (ag, i * sizeof(T));
}
Third, why do this when again, you have std::vector? All you need to do is call the resize() method to resize the vector.
See what I mean when I stated you
must know what you're doing? If you're asking us "where to delete the memory", then frankly, you're not ready for this type of programming where you're handling dynamically allocated memory. But again, there is no need to do this type of programming at all for your purposes.
Your program is written poorly from the beginning. Trying to answer your question concerning a syntax error will just encourage you to do more of the same bad programming.
Regards,
Paul McKenzie