1
votes

I am having troubles to use the enum defined in the separate module. When I try to access it, I am getting "Undefined identifier" error:

// CodeEnum.d

enum CodeEnum
{
    OK = 200,
    FAIL = 400
}

unittest
{
    auto e = CodeEnum.OK; // Works!
}

-

// Reply.d

import CodeEnum;

unittest
{
    auto.e = CodeEnum.OK; // Error: undefined identifier 'OK'
}

What am I doing wrong?

By the way, I've also posted this to the digitalmars-d-learn, but I don't see my email anywhere on the internet (list archive or forum) - is the list moderated in some way?

2
The newsgroup isn't moderated but it might have just randomly dropped the message... the server has had a few periods of outage this week (I think the admins are moving it to a new location but i'm not really sure) - Adam D. Ruppe
@AdamD.Ruppe Thank you, I will keep that in mind! - Nemanja Boric

2 Answers

6
votes

Since the module is called CodeEnum, CodeEnum.OK refers to a symbol OK in the module CodeEnum.

Use CodeEnum.CodeEnum.OK, or use a selective import: import CodeEnum: CodeEnum;, or give the module or the enum a different name.

2
votes

Your module name and enum name are in a conflict. Rename either the enum or the module name for your code to compile.