Timeline for In C++, when should I use final in virtual method declaration?
Current License: CC BY-SA 3.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 2, 2016 at 22:36 | comment | added | manlio | Unfortunately there isn't a +2 button. To date this seems to me the best way to bring non-virtual interfaces and multi-level inheritance together. | |
Jan 1, 2016 at 9:07 | comment | added | user204677 |
@DavidPacker It tripped me up too when I first encountered it. Maybe I should just make it protected to avoid confusing others. I ended up putting a comment, at least, describing how private virtual functions can still be overridden.
|
|
Jan 1, 2016 at 9:02 | comment | added | Andy | I thought having it set to private would not even compile. For example neither Java nor C# allow that. C++ surprises me every day. Even after 10 years of programming. | |
Jan 1, 2016 at 7:59 | history | edited | user204677 | CC BY-SA 3.0 |
added 134 characters in body
|
Jan 1, 2016 at 7:17 | comment | added | user204677 |
@DavidPacker protected might make a bit more intuitive sense. I just prefer to reach for the lowest-visibility possible whenever I can. I think the reason the language is designed this way is that, otherwise, private virtual member functions would make no sense whatsoever outside the context of friendship, since no class but a friend would then be able to override them if access specifiers mattered in the context of overriding and not just calling.
|
|
Jan 1, 2016 at 7:15 | comment | added | user204677 |
@DavidPacker private doesn't extend to overridding (a bit counter-intuitive). Public/protected/private specifiers for virtual functions only apply to callers and not to overriders, put crudely. A derived class can override virtual functions from its base class regardless of its visibility.
|
|
Jan 1, 2016 at 6:55 | comment | added | Andy |
How do you plan to override the private method inside your Vehicle class? Didn't you mean protected instead?
|
|
Jan 1, 2016 at 6:49 | history | edited | user204677 | CC BY-SA 3.0 |
added 26 characters in body
|
Jan 1, 2016 at 6:42 | history | edited | user204677 | CC BY-SA 3.0 |
added 254 characters in body
|
Jan 1, 2016 at 6:34 | history | edited | user204677 | CC BY-SA 3.0 |
added 254 characters in body
|
Jan 1, 2016 at 6:25 | history | edited | user204677 | CC BY-SA 3.0 |
added 79 characters in body
|
Jan 1, 2016 at 6:20 | history | answered | user204677 | CC BY-SA 3.0 |