Function definition in multiple modules

simendsjo simendsjo at gmail.com
Thu Mar 29 02:16:42 PDT 2012


On Thu, 29 Mar 2012 10:33:03 +0200, Martin Drasar <drasar at ics.muni.cz>  
wrote:

> Hi,
>
> I have a class that implements a lot of interfaces and I would like to
> separate the definition into different files, i.e. implementation of one
> interface in one file. Something akin to this C++ code:
>
> a.cpp:
>
> class A
> {
>   void b();
>   void c();
> };
>
> b.cpp:
>
> void A::b() {}
>
> c.cpp:
>
> void A::c() {}
>
> Is there a way to do it in D easily? Do I have to use UFCS?
>
> Thanks,
> Martin

D has interface files, .di. These can be automatically generated by the  
compiler using the -H switch.

So you code your class normally:
a.d:
class A
{
     void a() {}
     void b() {}
}

$ dmd -H a.d
$ cat a.di
// D import file generated from 'a.d'
class A
{
     void a()
{
}
     void b()
{
}
}


More information about the Digitalmars-d-learn mailing list