c++ - Returning value from shared pointer vector string -
i'm trying implement return method class want use smart pointers. have:
std::shared_ptr<std::vector<std::string>> data;
i want access last value function:
std::string& rear() { };
how access values shared_ptr?
i think this:
std::string& rear() { assert(data.get() != 0 && !data->empty()); return *(*data).rbegin(); };
*data
vector(*data).rbegin()
returns reverse iterator pointing last element*(*data).rbegin()
dereferences iterator, getting value (a reference)
Comments
Post a Comment