c++ - Is this function's use of vector useless? -


i saw earlier , doesn't make sense me:

void generate(std::vector<float> v) {  float f = generate_next_float();  v.push_back(f); } 

if v sent reference or pointer, make sense. instead sent value, , therefore copied function, right? done v useless once function terminates v out of scope, deleted.

am right?

that is, function generate_next_float() might something, not useless, use of vector here seems pointless. f not depend on it, , nothing returned.

yes, far vector concerned, generate() function pointless; changes v won't visible caller.

i have feeling author of generate() missed pass reference overlook, not plan :-)


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -