pbclone always uses pbref (possible slicing)

I always thought a function entry/exit is either pbclone (pass-by-value) or pbref (pass-by-reference) but never both. Now I know a pbclone always[1] uses a pbref somewhere.

Special case — if a copy ctor parameter is missing the “&”, then the pbclone will call the same ctor pbclone recursively — infinite recursion and stack overlow.

Note standard c++ copier has signature (MyClass const & rhs) . So the original arg object is first passed by reference into the copier. Occasionally this is non-trivial.

What if the arg object is a child of MyClass? Slicing ! The rhs variable can’t access the fields added by the child class.

[1] except the trivial case where the the argument is not an object but a literal

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s