www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Final class

reply "Daniel Kozak" <kozzi11 gmail.com> writes:
Are all methods in final class non-virtual or must be explicity 
marked as a final too?
Jul 11 2013
parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Friday, July 12, 2013 07:03:07 Daniel Kozak wrote:
 Are all methods in final class non-virtual or must be explicity
 marked as a final too?
They're virtual if they override base class functions, but they're definitely all final. So, the compiler _should_ optimize the functions in a final class which don't override anything so that they're non-virtual. However, I'm not sure that there's actually any guarantee that final methods which don't override anything will actually be made non-virtual. It's an optimization based on the fact that the compiler can determine that it can be made non- virtual rather than it explicitly being made non-virtual by the programmer, so the compiler might not do it. It _should_, but I'm not sure that it's guaranteed to. - Jonathan M Davis
Jul 11 2013
parent "Daniel Kozak" <kozzi11 gmail.com> writes:
On Friday, 12 July 2013 at 05:13:44 UTC, Jonathan M Davis wrote:
 On Friday, July 12, 2013 07:03:07 Daniel Kozak wrote:
 Are all methods in final class non-virtual or must be explicity
 marked as a final too?
They're virtual if they override base class functions, but they're definitely all final. So, the compiler _should_ optimize the functions in a final class which don't override anything so that they're non-virtual. However, I'm not sure that there's actually any guarantee that final methods which don't override anything will actually be made non-virtual. It's an optimization based on the fact that the compiler can determine that it can be made non- virtual rather than it explicitly being made non-virtual by the programmer, so the compiler might not do it. It _should_, but I'm not sure that it's guaranteed to. - Jonathan M Davis
Thanks
Jul 11 2013