mercredi 9 juin 2021

How to Change the Code After inserting Object in Vectors

In Movie.hpp

#ifndef MOVIE_H
#define  MOVIE_H

class Movie
{
  private:
    std::string title;
  public:
    std::string getTitle() const {return this->title;}   
    void setTitle(std::string newTitle){this->title = newTitle;}
};

#endif

In Actor.hpp

#ifndef ACTOR_H
#define  ACTOR_H

#include "Person.hpp"
#include "Movie.hpp"

class Actor: public Person
{
  private:
    std::vector<Movie> movieList;
  public:
    void addMovie(Movie newMovie){this->movieList.push_back(newMovie);}
    void printMovies()
    {
      for(Movie movie: this->movieList)
      {
        std::cout << movie.getTitle() << '\n';
      }
    }
};

#endif

What are the changes will be there in the code if I add a separate class

class Role {
private:
   Actor* actor;
   Movie* movie;
};

and store collection of such objects inside Movie and Actor

std::vector<Role> movieList; //inside Actor

std::vector<Role> actorList; //inside Movie

Someone please help me out by editing the code in Movie.hpp and Actor.hpp using the "Role" Object defined above.

Aucun commentaire:

Enregistrer un commentaire