100DaysOfGameDev: Day 20

Today I learned about the concept of slicing, which is not really a thing in Java but exists in the realm of C++. It's when you copy an object B, but the pointer type is of its base A and only the part of A is getting copied, and members of B get left out. Sounds spooky to me, but the author assures that sometimes it's what the developer wants. Ways to prevent it is to either remove the copy constructor in the base class or make it private or protected so you will get an error. Then, the topic of move and copy semantics was discussed. Although it has been discussed in previous chapters already, this time it was more detailed. It also talked about the default behavior of compiler and how to prevent it, or otherwise make it more explicit. If you leave out constructor, copy, move, and destructor declarations, then the compiler will include default ones. You can get rid of it by using the =delete;, or if you want to explicitly show that default behavior is needed you can include =default;. Also, if you declare your own constructor, then the default will not be generated the same as in Java. Furthermore, if you declare a copy operation, move operation, or a destructor for a class, then no copy operation, move operation, or destructor is generated for that class. The book also talked about good practices for maintaining class invariants. However, this is something to be learned by experience, error, and trial. The next topic was operation overloading, but I will not bore you with that, since I believe it's quite boring to know the whole nitty-gritty details about it if you are not going to design your own library, but be a user instead. That's it for today, see you!