CPP Object Slicing


```typestruct A {	int a;}struct B: A {	int a;}void fill (A* z, int n) {	for (int i = 0; i < n; i++)		z[i].a = i;}main(){	B y[8];	fill(y, 8);	cout << y[2].a << endl;}// 4 not 2```
because fill function refer A but B is double sized memory



> [Object Slicing in C++ - GeeksforGeeks](https://www.geeksforgeeks.org/object-slicing-in-c/)

> [[C++] Object Slicing (오브젝트 슬라이싱)](https://pretending.tistory.com/entry/C-Object-Slicing-%EC%98%A4%EB%B8%8C%EC%A0%9D%ED%8A%B8-%EC%8A%AC%EB%9D%BC%EC%9D%B4%EC%8B%B1)

> [[C++] Object slicing](https://blog.seulgi.kim/2015/02/c-object-slicing.html)





