double * values; // instead of this,
std::vector<double> values; // I want this.
An API I’m using provides a result as double* pointer. I want to wrap this with the std::vector<double> type.
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.
You can’t wrap an array in a vector in place and expect the vector to operate on that array. The best you can do is give the vector the
double*and the number of values, which will have the vector make a copy of every element and put it in itself:And also, like Praetorian said, if the API you are using expects you to free the memory after using it, you might be interested in smart pointers. See Praetorian’s answer.