Alex Rivera | Logout

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

Asked 2012-01-10T02:20:03.080
21

suppose we have an object with the following interface:

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

Now, i access the property with an auto variable like this:

auto childs = node->getChilds();

what is the type of childs? a std::vector< something > or a reference to one?

Edit
Report

1 Answer

21

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

auto & childs = node->getChilds();

That will of course be a const reference.

answered 2012-01-10T02:22:42.433

Your Answer