c++11 - Passing const reference or shared pointer / vector and assign to non-reference member -


cpp check complaining construction:

void setthing(std::shared_ptr<thing> thething) { memberthing = thething; }

where memberthing std::shared_ptr<thing>.

when changing to: void setthing(const std::shared_ptr<thing>& thething);

cppcheck not complaining anymore.

i need shared pointer, can't guarantee thething exist forever, don't want have member reference. why const reference working when assigning not-reference member? , happens actually? shared pointer copied memberthing? did reference go?

and same question

void setthings(std::vector<std::shared_ptr<thing>> thethings) { memberthings = thethings; }

where memberthing std::vector<std::shared_ptr<thing>>.

when using construction, happening vector? copied? happens when original vector destroyed? can better use first version or second?

i quite confused const vector& can assigned vector (not-reference). idea anyway? best thing in situation? , why?


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -