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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -