A lightweight module for class extensions in D
Robert Fraser
fraserofthenight at gmail.com
Sat Dec 6 21:55:07 PST 2008
Nick Sabalausky wrote:
>> Unrelated (but the main reason I use visitors), I wish D could allow could
>> declaring a virtual function in the class definition but implement it
>> elsewhere (a la C++). So...
>>
>> module1.d:
>> ----------
>> module module1;
>> class A { int foo(int x); }
>>
>> module 2.d:
>> -----------
>> module module2;
>> import module1;
>> int A.foo(int x) { return x; }
>
> Sounds like you're thinking of something like C#'s partial classes, but with
> the ability to say "Compiling should fail if I've forgotten to define bodies
> for any of the following functions"?
That's one way to think about it. I was thinking that in a C++ header
file you o this:
class A { public: int foo(int x); }
And in another file you do this:
#include "A.h"
int A::foo(int x) { }
If foo is not implemented, the failure is at link time.
More information about the Digitalmars-d
mailing list