c++ - How to pass vector as function argument to pointer -
this question has answer here:
- how convert vector array in c++ 7 answers
i try pass vector function argument pointer compiler return error.
error: cannot convert 'std::vector' 'float*' in assignment
when have passed array in same way works perfectly. wrong here? possible assign vector pointer?
vector <float> test; class data { float *pointer; int size; public: void init(vector <float> &test, int number); }; void data::init(vector <float> &test, int number) { size= number; pointer = test; }
if want pointer array managed vector, that's
pointer = test.data(); // c++11 or later pointer = test.empty() ? null : &test[0]; // primeval dialects
beware invalidated if vector destroyed, or reallocates memory.
Comments
Post a Comment