c++ - Passing a pointer to a function expecting a vector -


there function can not edit has following declaration:

void foo(std::vector<uchar>& vector_to_filled_with_data); 

i want call function want fill pointer instead:

void method_that_would_called_from_another_place(){      uchar* to_be_filled =/*new uchar[n]*/;      foo(to_be_filled); } 

p.s. commented part optional.. can erase or leave it. know totally bad behavior. however, native-manged wrapper have deal raw pointers.

edit: want data live out of scope getting 'vec.data' not option. want thread-safe

you need create vector, create array , copy data vector:

std::vector<uchar> to_be_filled; foo(to_be_filled); uchar* ptr = new uchar[to_be_filled.size()]; std::copy(to_be_filled.begin(), to_be_filled.end(), ptr); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -