Manual Vector::clear() problem

Clear - removes all elements in vector. I know that I can #include <vector>, but this assignment has us create the class manually.

I am having some problems when using this method. Here's my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 // Create a stack of strings
  vector<string> stringVector;
  stringVector.push_back("Chicago");
  stringVector.push_back("Denver");
  stringVector.push_back("London");

  stringVector.pop_back();
  cout << endl;

   for (int i = 0; i < stringVector.getSize(); i++)
	{
        cout << stringVector[i] << " ";
	}

  stringVector.clear();
  if (!stringVector.empty())
	  cout << "Not empty";
  else
	  cout << "Empty";


1
2
3
4
5
template<typename elementType>
void vector<elementType>::clear()
{
  delete [] elements;
}


Here's the error I get:
c:\users\kraigballa\documents\visual studio 2010\projects\homework\12vectortest\test.h(58): warning C4154: deletion of an array expression; conversion to pointer supplied
1>          c:\users\kraigballa\documents\visual studio 2010\projects\homework\12vectortest\test.h(57) : while compiling class template member function 'void vector<elementType>::clear(void)'
1>          with
1>          [
1>              elementType=std::string
1>          ]
1>          c:\users\kraigballa\documents\visual studio 2010\projects\homework\12vectortest\testvector.cpp(26) : see reference to class template instantiation 'vector<elementType>' being compiled
1>          with
1>          [
1>              elementType=std::string
1>          ]

Last edited on
Post the vector class (declaration).
Topic archived. No new replies allowed.