string object won't compile

askjfbd icadraic9 at gmail.com
Tue Mar 6 00:50:05 UTC 2018


On Monday, 5 March 2018 at 23:42:59 UTC, Adam D. Ruppe wrote:
> On Monday, 5 March 2018 at 23:34:50 UTC, askjfbd wrote:
>> string.d
>
> The problem is you named the file string.d and didn't give a 
> `module xxxxx;` statement in the code, so the compiler assumed 
> the module is named after the file.... and thus introduced a 
> local name `string` referring to the module, overriding the 
> built in one.
>
> You can still refer to the built in one by saying `.string foo 
> = "bar";` - yes, the leading dot, which tells it to use the 
> global instead of local name.
>
> Or by putting `module mytest.string;` at the top, so the module 
> has a two-part name (I recommend this in all cases anyway btw, 
> it is the best way to avoid conflicts as you import more 
> modules).
>
> Or just renaming the file from string.d to 
> almost_anything_else.d, which will also avoid the local name 
> override.

Thanks for the precise advice. How foolish I was and how quickly 
you gave me the answer! I'll have to learn a lot more about D and 
more about modules. Since C and common lisp, which I have learned 
so far, have almost nothing to do with name conflicts, I couldn't 
imagine that I was still wrong. :) Thank you.


More information about the Digitalmars-d-learn mailing list