C++ Vector of pointers

后端 未结 4 995

For my latest CS homework, I am required to create a class called Movie which holds title, director, year, rating, actors etc.

Then, I am required to read a file which c

4条回答
  •  迷失自我
    2021-01-31 09:52

    As far as I understand, you create a Movie class:

    class Movie
    {
    private:
      std::string _title;
      std::string _director;
      int         _year;
      int         _rating;
      std::vector actors;
    };
    

    and having such class, you create a vector instance:

    std::vector movies;
    

    so, you can add any movie to your movies collection. Since you are creating a vector of pointers to movies, do not forget to free the resources allocated by your movie instances OR you could use some smart pointer to deallocate the movies automatically:

    std::vector> movies;
    

提交回复
热议问题