Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, you can have a private virtual member function, and it can be overridden in a child class (unless declared final), apparently.

I too thought that sounded insane, so I just looked it up. I've been programming C++ for twenty five years and the thought of wanting to do this have never ever occurred to me...



It could make sense if you have a method that you want derived classes to be able to override but not to be able to call directly.

This is, admittedly, a pretty niche case but certainly not inconceivable.


Except the derived class can simply change the visibility of the override, so...


TIL.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: