FlexBox has been marked as final


#1

Hi, any particular reason why this has been done?

thx


#2

Well yes - the same reason as for any other final class!

If there’s no sensible reason why anyone would need to inherit from it, marking a class as final stops beginners who don’t understand inheritance vs composition from making some silly mistakes.


#3

I added an iteration function as I want to be able to iterate over nested structures, and found myself writing the same recursive iteration code repeatedly. The most sensible place to put it was on a subclass of FlexBox - other than that I need some static function on a utility class. I was just surprised with 5.1.2 that I’d been stopped from doing this.

bool iterate( FlexBox& flex, std::function<bool( Component * )> fn )


#4

Ask any respectable C++ guru and they’ll tell you that the best way to do that is with a free function, and definitely not by subclassing a non-virtual class!

It’ll be nice if we one day get uniform call syntax, which would make the calls look a little prettier, but honestly, free functions are less error-prone.


#5

i’l consider this my lesson for the day then, thx.


Reading tips for better C++