Low Level Programming Sessions Summary 11
6th December
This week we talked about overloading of functions. I didn't really understand what it was about if I'm honest. As far as I remember it's about using more parameters than would otherwise be allowed in a function to achieve certain effects. We can define behaviours by overloading and make things easier.
My understanding is limited, but from what was said we can use overloading to cast using operators such as the ++ and == signifiers. We can also use constants and returns to give objects certain values by forcing parameters on them.
We learnt a quick short hand trick to doing if statements which is "?:". In literacy I am an advocate of clarity over brevity as I think communication and understanding is more important than being able to write something quicker, as messages are easily miscommunicated and one shouldn't be making this harder. I take the same approach with code.
The other main thing we discussed was function pointers, which again, I'm still a bit confused on. Apparently, we've been using them all the time without knowing it. They are pointers to functions essentially, the () operator is used to dereference these pointers, just like the * does. It is essentially a pointer to a constant function in memory. They have hideous syntax, and if ever there was a use for auto and aliases, this would be it.
On an interesting note, the compiler will always run anything in brackets first, obeying the rules of BODMAS, just like we learned in GCSEs.
We learned about decltypes which seem like they can help cut through syntax yet again. Instead of using function pointer syntax, we use a decltype and pass it through. We can also make a class ID for each type and then use function pointers to pass each thing a type. They can also be used as a game state and we also use them in predicates.
Assignment work is mostly done. I'm glad it's mostly over. I feel I've learnt a lot, mostly just about the scale and complexity rather than technical nuances. Still, I managed to do it despite my doubts.
No comments:
Post a Comment