FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SOLVED: Classes and multiple files

 
Post new topic   Reply to topic     Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
Dark_Lite



Joined: 23 Mar 2005
Posts: 2

PostPosted: Wed Mar 23, 2005 4:07 pm    Post subject: SOLVED: Classes and multiple files Reply with quote

Coming from Java, I'm used to (generally) having one class per file. Right now I have two files: test1.d and test2.d.

Contents of test1.d:

Code:

import std.c.stdio;

class Test {
   this() {
      printf("It works!");
   }
}


Contents of test2.d:

Code:

import std.c.stdio;
import test1;

void main() {
   Test test = new Test();
}


That's what they are right now. The "import test1;" is something I gleaned from the examples. However it won't compile. This is the output:

Code:

C:\dmd\bin> dmd test1.d test2.d
test2.d(5): identifier 'Test' is not definede
test2.d(5): Test is used as a type
test2.d(5): variable test2.main.test voids have no value

...


If anyone needs more output just ask. It's all about line 5... Which is where the Test object is declared. Obviously it's not seeing my other class file. Could someone help please?


Last edited by Dark_Lite on Wed Mar 23, 2005 4:31 pm; edited 1 time in total
Back to top
View user's profile Send private message
Derek Parnell



Joined: 22 Apr 2004
Posts: 408
Location: Melbourne, Australia

PostPosted: Wed Mar 23, 2005 4:17 pm    Post subject: Re: Classes and multiple files Reply with quote

Dark_Lite wrote:
Coming from Java, I'm used to (generally) having one class per file. Right now I have two files: test1.d and test2.d.

Contents of test1.d:

Code:

import std.c.stdio;

class Test {
   this() {
      printf("It works!");
   }
}


It sounds like its using a different test1.d than you are expecting it to use. Have you got any other test1.d files hanging around in anywhere?
Contents of test2.d:

Code:

import std.c.stdio;
import test1;

void main() {
   Test test = new Test();
}


That's what they are right now. The "import test1;" is something I gleaned from the examples. However it won't compile. This is the output:

Code:

C:\dmd\bin> dmd test1.d test2.d
test2.d(5): identifier 'Test' is not definede
test2.d(5): Test is used as a type
test2.d(5): variable test2.main.test voids have no value

...


If anyone needs more output just ask. It's all about line 5... Which is where the Test object is declared. Obviously it's not seeing my other class file. Could someone help please?


It works correctly for me. Here is the output I get ...
Code:


C:\temp>type test1.d
import std.c.stdio;

class Test {
   this() {
      printf("It works!");
   }
}
C:\temp>type test2.d
import std.c.stdio;
import test1;

void main() {
   Test test = new Test();
}
C:\temp>dmd test1.d test2.d
C:\DPARNELL\DMD\BIN\..\..\dm\bin\link.exe test1+test2,,,user32+kernel32/noi;

C:\temp>test1
It works!
C:\temp>

_________________
--
Derek
skype name: derek.j.parnell
Back to top
View user's profile Send private message
Dark_Lite



Joined: 23 Mar 2005
Posts: 2

PostPosted: Wed Mar 23, 2005 4:22 pm    Post subject: Re: Classes and multiple files Reply with quote

Derek Parnell wrote:
Dark_Lite wrote:
Coming from Java, I'm used to (generally) having one class per file. Right now I have two files: test1.d and test2.d.

Contents of test1.d:

Code:

import std.c.stdio;

class Test {
   this() {
      printf("It works!");
   }
}


It sounds like its using a different test1.d than you are expecting it to use. Have you got any other test1.d files hanging around in anywhere?
Contents of test2.d:

Code:

import std.c.stdio;
import test1;

void main() {
   Test test = new Test();
}


That's what they are right now. The "import test1;" is something I gleaned from the examples. However it won't compile. This is the output:

Code:

C:\dmd\bin> dmd test1.d test2.d
test2.d(5): identifier 'Test' is not definede
test2.d(5): Test is used as a type
test2.d(5): variable test2.main.test voids have no value

...


If anyone needs more output just ask. It's all about line 5... Which is where the Test object is declared. Obviously it's not seeing my other class file. Could someone help please?


It works correctly for me. Here is the output I get ...
Code:


C:\temp>type test1.d
import std.c.stdio;

class Test {
   this() {
      printf("It works!");
   }
}
C:\temp>type test2.d
import std.c.stdio;
import test1;

void main() {
   Test test = new Test();
}
C:\temp>dmd test1.d test2.d
C:\DPARNELL\DMD\BIN\..\..\dm\bin\link.exe test1+test2,,,user32+kernel32/noi;

C:\temp>test1
It works!
C:\temp>


That's strange... It works for me too now.

Must be because I had notepad open while trying to compile Smile
Back to top
View user's profile Send private message
Derek Parnell



Joined: 22 Apr 2004
Posts: 408
Location: Melbourne, Australia

PostPosted: Wed Mar 23, 2005 4:29 pm    Post subject: Sorry about reposts. Reply with quote

I think I found a 'bug' in phpBB. I pressed F5 (refresh browser) and it sent the post again. Sorry.
_________________
--
Derek
skype name: derek.j.parnell
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Wed Mar 23, 2005 6:54 pm    Post subject: Reply with quote

You should still be able to delete your own posts if this happens, though. I'll do it for you here.

-JJR
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Tutorials All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group