If I have
void f(vector<object> *vo) {
}
And I pass the address of a vector to f
vector<object> vo;
f(&vo);
How would I use push_back() to add to the vector?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Dereference the pointer:
Note this is a basic concept of the language, you may benefit from reading a good book.
Note this has a glaring shortcoming:
To make your function safe, you need to correctly handle all valid pointer values (yes, null is a valid value). Either add a check of some kind:
Or make your function inherently correct by using a reference:
Now the onus is on the caller of the function to provide you with a valid reference.