slicing

来源:互联网 发布:linux 调试工具 编辑:程序博客网 时间:2024/05/08 09:53

"Slicing"is where you assign an object of a derived class to an instance of abase class, thereby losing part of the information - some of it is"sliced" away.

For example,

class A {  int a;};
class B : public A{int b;};

So an object of type B has two data members, f and b

Then if you were to write this:

B b;A a = b;

Then the information in b about member b is lost in a.

原创粉丝点击