View previous topic :: View next topic |
Author |
Message |
Dark_Lite
Joined: 23 Mar 2005 Posts: 2
|
Posted: Wed Mar 23, 2005 4:07 pm Post subject: SOLVED: Classes and multiple files |
|
|
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 |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Wed Mar 23, 2005 4:17 pm Post subject: Re: Classes and multiple files |
|
|
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 |
|
|
Dark_Lite
Joined: 23 Mar 2005 Posts: 2
|
Posted: Wed Mar 23, 2005 4:22 pm Post subject: Re: Classes and multiple files |
|
|
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 |
|
Back to top |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Wed Mar 23, 2005 4:29 pm Post subject: Sorry about reposts. |
|
|
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 |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Wed Mar 23, 2005 6:54 pm Post subject: |
|
|
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 |
|
|
|