auto from const std::vector<>&; object or reference?

前端 未结 3 1456
没有蜡笔的小新
没有蜡笔的小新 2020-12-18 19:01

suppose we have an object with the following interface:

struct Node_t {
 ... const std::vector< something >& getChilds() const;
 } node;

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-18 19:26

    It's an std::vector. If you want a reference, you can do this:

    auto & childs = node->getChilds();
    

    That will of course be a const reference.

提交回复
热议问题