0

Hello does anyone of you know how to put an array into a class whenever I put an array into a class it gets "error: initializer" I'm using codeblocks btw...

    class TVshow {
       private:
                std::string rating;
       public:
    std::string title;
    std::string director;
    std::string valid_rating[] = {"G", "PG", "PG-13", "R", "NR"};
    TVshow(std::string aTitle, std::string aDirector, std::string aRating) {
        title = aTitle;
        director = aDirector;
        setRating(aRating);
    }
    void setRating(std::string aRating) {
        rating = aRating;
    }

};
MikeCAT
  • 73,922
  • 11
  • 45
  • 70
yvez
  • 11
  • 2

1 Answers1

0

You'll need to provide the size.

std::string valid_rating[5] = {"G", "PG", "PG-13", "R", "NR"};

You can initialize on declaration as it is now or better would be inside a constructor.

abdullahQureshee
  • 322
  • 2
  • 12