C++, vectors, pointers and objects confusion
<p>I am working on a project as a homework for my university course of Systems Programming.
I got really confused with the matter of Pointers, Vectors, stacks and heaps.</p>

<p>Using C++.
I have to get a vector of objects which are courses, and those courses objects have several different fields.
What I did was this:</p>

<pre><code>vector&lt;CoursesObject&gt; coursevector;
</code></pre>

<p>and then I created my Courses Object class, which contains the space left in course and name of course fields.
Now I want to add a new course, I do:</p>

<pre><code>CoursesObject *theCourse = new CoursesObject(name, space);
</code></pre>

<p>now I want to add it to the handler vector:</p>

<pre><code>coursevector.push_back(*theCourse);
</code></pre>

<p>With all I know, I created a vector of Courses objects on the stack, and made a new pointer to a new course that is on the heap, and added to the handler vector the pointer theCourse that points to the course object in the heap. Is what I said correct?</p>

<p>When I try to delete those course objects, I do:</p>

<pre><code>for(int i=0; i&lt;coursevector.size(); i++)
    delete coursevector.at(i);
</code></pre>

<p>which gives me an error that it is not a pointer. But haven't I added to the coursevector a POINTER to the course object?</p>

<p>Please somebody explain, I have to handle the memory correctly and it seems that I am not getting it right.</p>
