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;
      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;


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?

What data type are you using for your string? Is it the string type or a char*? It also looks like your code to insert is not complete. What happenes if you want to insert into the middle of the array? How do you get the values into the the array after the insert point? I would also suggest making your code to resize the array its own function and make it private in your class. than you just have a call to rersize if the array isnt big enough and the code to insert the element.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.