switchcase can’t identify enum values from another namespace [closed]

  c++, enums, namespaces, switch-statement

I need to compare a large number of strings. To do that I’m using a switchcase and an enum. Some values i need to compare are identical to ‘commands’ in c++ so to avoid errors i tried putting the enum inside a namespace named kwd. The enum and switchcase are in separate header files included in an implementation file, i also tried to include the enum file in just the switchcase file but neither worked.

The error thrown is error: ‘Valarray_operators’ is not a member of ‘kwd’ for all entries. The source code i used to implement the namespace is as follows:

namespace kwd { //define namespace
    enum Options{ //enumerate alternatives
        Option_Invalid,
        assert,
        isalpha,
        isblank,
        iscntrl,
        Valarray_operators
        //etc...
        };
//later
Options resolve(std::string input){ //find enum values
        static const std::map<std::string, Option> optionStrings { //inputmap
            { "assert", assert },
            { "isalpha", isalpha },
            { "isblank", isblank },
            { "iscntrl", iscntrl },
            { "Valarray_operators", Valarray_operators }
            //etc...
            };
//finally closing with
        auto itr = optionStrings.find(input); //search for hit
        if( itr != optionStrings.end() ) {
            return *itr;
        }
    return Option_Invalid;
    }
}

i then compare the result with the following switch:

string commentMake(string commentarray[]) {
        int commentarraylen =sizeof(commentarray)/sizeof(commentarray[0]);
        kwd::Options resolveOption(string input);
        string comment = "";
        for(int i =0; i < commentarraylen; i++){
            switch (resolveOption(commentarray[i])){
            case kwd::Option_invalid:
            comment += commentarray[i] + " ";
            break;
            case kwd::assert:
            comment += "Evaluate assertion ";
            break;
            case kwd::isalpha:
            comment += "Check if character is alphabetic ";
            break;
            case kwd::isblank:
            comment += "Check if character is blank ";
            break;
            case kwd::iscntrl:
            comment += "Check if character is a control character ";
            break;
            case kwd::Valarray_operators :
            comment += "";
            break;
            }
      }
}

but as mentioned above this simply returns error: ‘Valarray_operators’ is not a member of ‘kwd’ sometimes asking if the command was intended to be part of the std namespace.
Why can’t my code identify the enum values? Other solutions I’ve found seem to use this method but it doesn’t seem to work.

Source: Windows Questions C++

LEAVE A COMMENT