Hi, I've been using Borland C++ Builder 4 for a while now, and I've been plagued recently by a logic error in their vector code. I don't know if anybody who has the same compiler ran into the same problem, but I figured I'd post the error and what I did to fix it in case anybody is having the same problems I am.

The error is this: you can't resize a vector of int's. When you try, you get an error stating that there is ambiguity between two versions of the insert member function. Here's their code:

template <class T, class Allocator>
void vector<T,Allocator>::resize (size_type new_size)
{
T value;
if (new_size > size())
insert(end(), new_size - size(), value);
else if (new_size < size())
erase(begin() + new_size, end());
}

So, if the template class is, for example, string, then their call to insert in line 6 is: insert(int*, int, string);. If the template class is int, however, then the call is: insert(int*, int, int);. This fails, however, because there is another version of insert that also takes an int* and two int's (actually one of them is a const int&, but it is functionally the same thing for this purpose) as its argument. Thus the compiler does not know which one to use and throws an error. Here is how I fixed the issue if anybody cares:

template <class T, class Allocator>
void vector<T,Allocator>::resize (size_type new_size)
{
T value;
if (new_size > size())
for(int i = size(); i < new_size; i++)
push_back(value);
else if (new_size < size())
erase(begin() + new_size, end());
}

It's nothing fancy, but it works.

You're Welcome,
Paul Siegel