Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to ensure that member functions are virtual in D?

Tags:

d

As I understand it, all member functions are virtual in D but the compiler is free to make functions non-virtual if it sees that they are never overridden.

What I'm not clear on is what happens when you compile a module in which member functions are not overridden and then import that module somewhere else where you override a member function. I don't think it re-compiles the original module. Does it simply assume that any member function with external linkage is virtual?

like image 615
Ferruccio Avatar asked Apr 15 '09 11:04

Ferruccio


1 Answers

All D member functions are virtual by default. I don't think there's any compilers out there that actually make functions non-virtual as an optimization. You can do it manually though, by marking the class or the function as "final".

like image 93
FeepingCreature Avatar answered Jan 03 '23 00:01

FeepingCreature