Getters/Setters with std::vector<>.push_back(…)

前端 未结 1 1044
悲哀的现实
悲哀的现实 2021-01-21 00:14

For some reason this doesn\'t work. It compiles file, but no items are added to this vector when using a getter.

E.G.

class class_name {

    public:
            


        
1条回答
  •  广开言路
    2021-01-21 00:37

    Return the vector by reference if you plan to modify it:

    inline std::vector &get_numbers() { return m_numbers; }  
                            ^
    

    Without the ampersand a copy is returned.

    0 讨论(0)
提交回复
热议问题