Can/should we use the import "inside the class definition"?
That solves the problem described here.
Now that I wrote this, it all seams obvious.
Maybe it could be explicit on the D modules page.
here it is anyway:
########## details ###########
I had a few classes on the same source file
that compiled with no problem.
when I separated then into 1 file/class
I get:
./parse/Class.d: class Class forward reference of base class Struct
I double (triple) check in Class.d that the only ref I have to
Struct is in "public class Class : Struct"
(and the import)
What might be happening (guessing, I didn't check to see how
how the compiler does it) is:
Struct imports Class because a struct can contain a class.
Class imports Struct because a class is a struct.
When Struct is parsed it finds import Class and gets it
when parsing Class for the import on Struct it finds import Struct
but knows that going to parse Struct would enter a loop so
it quits giving a simple message.
So to test this I moved all the imports into the classes,
let me make sure that is clear:
###########
module parse.Struct;
import parse.Element;
public class Struct : Element
{
import parse.Enum;
import parse.Function;
import parse.Class;
...
Class[] classes;
}
############
module parse.Class;
import parse.Struct;
public class Class : Struct
{
}
############
So when module Class is parsed because of the import Class on the Struct
class the compiler already knows that Struct is a class.
(unfortunatly I also have a method named parse, so let me rename something...)
Yes! That did it!
So now back to my question:
Can/should we use the import "inside the class definition"?
the only import I'm leaving before the class definition is the
import that contains the super class.
Are the access modifiers (protected, private) respected on that case?
(I guess I can do a simple test if nobody is sure about this)
I know that imports cannot be used in a function body.
(I just tried to import inside a function and got
"./parseD/Parser.d(440): found 'import' instead of statement"
from the compiler)
Ant
(I can already see the answer from Walter:
A post with only one word, either 3 or 2 letters (yes or no) )