Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

References and Object Slicing

I don't have my Effective C++ with me and this is bugging me so much that I have to ask for my own sanity. Given

class Foo : public Bar{}

void MyFunc(Bar &_input);

If I pass in a Foo, am I tangling with the slicing problem or have I avoided it?

like image 653
wheaties Avatar asked May 12 '10 19:05

wheaties


1 Answers

Not a problem, because you're passing in a reference. You're not creating a new object, just letting MyFunc access the original object.

like image 187
Jason S Avatar answered Oct 06 '22 13:10

Jason S