how to implement a function in a different D source file

Omar zelux at gmx.us
Wed Nov 27 23:32:34 UTC 2019


Oh I see, it seems like the answers I'm getting imply that you 
have the option of a pure interface or pure implementation but not
a mix. I see how I could elaborate more on what I was asking 
about.

As long as you only import the file but not try to compile the 
same module twice right ?
So just to be clear, in D you can't do something like.

/+ a.d +/
void func1 () { /+ do stuff +/ }
void func2 () { /+ do stuff +/ }
void func3 () ;

/+ b.d +/
void func_x1 () { /+ do stuff +/   }
void func3   () { /+ true stuff +/ }

this forks into a second question but I think still fits this 
thread as it could just be seen as another form of the same 
question.
Is there a way to define some functions in the body of a class 
definition, and define others outside of it in other places in the
source file ?
example

/+ top.d +/
import stuff = other_stuff ;

class system {
     int           a,b,c,d ;
     float         x,y,z   ;
     stuff.struct1 p,i,e   ;
     stuff.struct2 l,t,v   ;

     int           test           (int      CMD) { /+ do stuff +/ }
     int           maintenance    (stuff.struct) { /+ do stuff +/ }
     int           connect        ()                     ;
     stuff.struct3 eval           (stuff.op[] pipeline)  ;
     void          reset          (int node)             ;
     void          save           (stuff.struct_x state) ;
     void          exportFile     (string name)          ;
     void          loadFromStream ()                     ;
     void          loadFromFile   ()                     ;
}

/+ implement those 7 functions here or in other files +/



More information about the Digitalmars-d-learn mailing list