single class in file

Jan Hanselaer jan.hanselaer at gmail.com
Sat May 5 14:40:20 PDT 2007


"Derek Parnell" <derek at psych.ward> schreef in bericht 
news:1vzymj9lmr9rr.1m84406w2ct0f$.dlg at 40tude.net...
> On Sat, 5 May 2007 22:11:03 +0200, Jan Hanselaer wrote:
>
>> Hi
>>
>> I'm trying to make a class in a module. A bit inspired by java where one
>> class is one object.
>> Altough I tought this would work in D too.
>> The code here works. But I just want the class Test in that file. And 
>> then I
>> want to use it in my main program (in another file).
>
> Ok, here is one way you can do that ...
>
> // file :  test.d
>
>  class Test
> {
>       char[] name;
>       int nr;
>
>       this()
>       {
>          name = "test";
>          nr = 1;
>       }
> }
> // ------- EOF --------
>
> // file: app.d
> import test;
> void main(){}
> // ------- EOF --------
>
>
> Then at the command line ...
>
> dmd app test
>
> Or if you want to do it in steps ...
>
> dmd test -c
> dmd app test.obj
>
> Or use one of the 'build' tools (eg. rebuild or bud) ...
>
> bud app
>
> The D compiler needs to have a 'main' routine to be able to link the file
> together. If you want to compile a file that does not have a main routine,
> you need to use the "-c" -switch, which stands for 'compile only; no
> linking'. And once you have all your files separately compiled, you need 
> to
> link the application, so you supply the source file that contains the
> 'main' routine plus all the object files it needs on the command line.
>
>
> The 'build' tools help automate the compilation steps required.
>
> -- 
> Derek Parnell
> Melbourne, Australia
> "Justice for David Hicks!"
> skype: derek.j.parnell

That's the information I needed. Thanks a lot! 




More information about the Digitalmars-d-learn mailing list