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

后端 未结 3 1903
走了就别回头了
走了就别回头了 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:07

    For class members, you do not initialise them where you declare them (as the list of members is just that: a list of types and names), but instead in the constructor's member initialisation list.

    Like this:

    class Menu
    {
        std::vector mi;    // no initialiser here
    
        Menu() : mi(20) {};          // but in the ctor-initializer instead
    };
    

提交回复
热议问题