Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8768247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:01:13+00:00 2026-06-13T17:01:13+00:00

I am working on a project as a homework for my university course of

  • 0

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.

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:

vector<CoursesObject> coursevector;

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:

CoursesObject *theCourse = new CoursesObject(name, space);

now I want to add it to the handler vector:

coursevector.push_back(*theCourse);

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?

When I try to delete those course objects, I do:

for(int i=0; i<coursevector.size(); i++)
    delete coursevector.at(i);

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?

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:01:14+00:00Added an answer on June 13, 2026 at 5:01 pm

    You do not need to use new at all.

    //This vector stores CoursesObject objects,
    //not pointers to CoursesObjects.
    vector<CoursesObject> coursevector;
    //Construct theCourse with automatic storage
    //duration.
    CoursesObject theCourse(name, space);
    //Copy theCourse into coursevector
    coursevector.push_back(theCourse);
    //theCourse will be automatically destroyed.
    //coursevector (and all the objects that it contains)
    //will be automatically destroyed.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on my first homework project in a web programming class, which is
I'm working on a homework project that requires me to create an object from
I am working on a homework project in which we need to generate a
I'm working on a homework assignment (a project), for which one criterion is that
I'm working on a mutation algorithm for a homework project and I'm stumped at
I'm working on a homework project involving a bomb written in compiled c which
I'm working on a homework project where we implement sessions (can't use HTTPSession) using
I’m working on a homework project compare performance of Fast Fourier Transform on CPU
I am working on a project involving Dynamic Programming and am struck on this
I am working on a homework project that should implement a board game between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.