c++ - If you include const in a function, is & redundant? -


will 2 function specifications below compile same thing? can't see copy needed if you're using const. if aren't same, why?

void(const int y); void(const int& y); 

not same. if argument changes after it's passed (e.g. because it's changed thread), first version unaffected because has copy. in second variant, function called may not change argument itself, affected changes y. threads, might mean requires mutex lock.


Comments

Popular posts from this blog

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

javascript - Create a stacked percentage column -