Error creating a size for a vector of Structs C++

后端 未结 3 1948
走了就别回头了
走了就别回头了 2021-01-26 02:31

This is for a project I am doing for my college class and I could not find an answer for this that worked for me anywhere. Its very likely I did not understand the answers thou

3条回答
  •  灰色年华
    2021-01-26 03:13

    You can do this in C++11 like so

    class Menu
    {
    private:
        std::vector mi = std::vector(20);
    };
    

    or if you are stuck using C++03 you will need to initialize it in the constructors initializer list

    class Menu
    {
    public:
        Menu() : mi(20) {}
    
    private:
        std::vector mi;
    };
    

提交回复
热议问题