void String::reserve(int sz) { if( sz <= capacity() ) return; while( m_allocSize < sz + 1 ) // 1 for '\0' m_allocSize *= 2; char *data = new char[m_allocSize]; for (int i = 0; i <= m_size; ++i) { // '\0' も含めてコピー data[i] = m_data[i]; } delete [] m_data; m_data = data; }
解説:
前: | 次: