100DaysOfGameDev: Day 21

Today I finished the chapter on operation overloading and started? that's right the chapter on operation overloading. Although, as much as it might confuse you ( it was indeed written in a way to confuse you ) the chapter I was reading before talked about logical operations and arithmetic operations overloading, however, the new chapter talks about special operators ( (), [], ->, ++, --, new, delete ), how to overload them, and how it has already been done for some classes, that are part of C++ standard. But before that, I should also mention that in the previous chapter, I learned about overloading a literal, which I think is quite useful. So, for example, you can define 123i, where i after the number would indicate would mean, that we want to construct a complex number complex{0, 123}, and it works. Another thing that you can override is implicit type conversion rules, so like if you have some user-defined type like Tiny, and you can say for example if we have function f(int) and we provide Tiny object instead, then how it would magically convert, that object to type int. That's also the part when my brain stopped braining. Now back to the topic of overloading special operators. One of the most notable ones is the overloaded subscripting operator. While in Java cringes, if you'd wanna access an element in ArrayList you would say a.get(i) and it's long and ugly, then in C++ you can access an element in vector ( the C++ counterpart of ArrayList ) with the beautiful syntax of v[i], because it is overloading const V& vector::operator[] (const K&) const and the other one ( lazy to type, sorry ). The function call operator overloading is also super cool, when you can call an object, it only has one method to execute and it will run it, with simple syntax obj(), which calls obj.exec(). Whereas in Java, if you'd write the Command Pattern, then you would manually call the obj.exec() which is ugly. The last topic I finished was dereferencing operator overloading, and it is the other topic that stopped my brain from braining. But I will not go into much detail, since you don't have to know about it anyways ( nor do I ). See you tomorrow, bye!