I’m researching about an issue that looks like this:
struct A { ... }
struct B : A { int more; }
void Method(A a) { ... }
It works like this: You pass an instance of B into Method, then in the body cannot access the more field anymore?
I tried to remember the name of this, but I can’t. Doing a search on Google just gives me nothing else.
Can anyone please give me the name so I can continue to research more?
I think actually what you’re talking about is slicing. When you pass a C++ object of some derived type by value through an argument of base type, the derived parts are “sliced off”, and they are not accessible even by casting to the derived type.
The solution to the problem is to use a reference argument — i.e.,
Then you can pass a
Bobject to this function without destroying theBparts.