引用和对象切片 [英] References and Object Slicing
本文介绍了引用和对象切片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我没有我的有效C ++与我,这是错误我这么多,我必须要求我自己的理智。给定
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);
如果我通过 Foo
我纠结于切片问题,还是我避免了?
If I pass in a Foo
, am I tangling with the slicing problem or have I avoided it?
推荐答案
不是一个问题,因为你传递一个引用。您不是创建一个新对象,只是让MyFunc访问原始对象。
Not a problem, because you're passing in a reference. You're not creating a new object, just letting MyFunc access the original object.
这篇关于引用和对象切片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文