I was coding up a class template a little while ago and I came across an error while debugging:
error: invalid conversion from âstd::basic_string<char>*â to âcharâ [-fpermissive]
It was in the code
template <typename T>
void ArrayList<T>::insert(const T& x,
unsigned int i)
{
if (i >= m_max)
cout << endl << "PANIC! Cannot insert file into un-indexed location! "
<< endl;
else
{
if (m_size > m_max - 1)
{
// Declare Varaibles
T *p;
*p = new T [m_max * 2]; // 129
for (unsigned int j = 0; j < m_size; j++)
p[j] = m_data[j];
m_data = p;
m_max *= 2;
// Deallocate Memory
delete [] p;
p = NULL;
}
for (unsigned int j = m_size; j > i; j--)
m_data[j] = m_data[j - 1];
m_data[i] = x;
m_size++;
}
return;
}
At line 129 the debugger failed because an string is defined as an array of characters. So, to work this I'd have to say:
p = new T[value_defined_elsewhere][m_max * 2];
However, as this class template is also meant to be used for non-array types I have to wonder how I should go about fixing the error.
Any suggestions?