How do I fix this error message error: no match for ‘operator[]’

codeblue

I am implementing a class that involves unordered_sets, and unordered_maps. When I go to run the program it gives me the following error

error: no match for ‘operator[]’ (operand types are ‘std::unordered_set<std::__cxx11::basic_string<char> >’ and ‘const string’ {aka ‘const std::__cxx11::basic_string<char>’})
     int points = Prizes[Codes[code]]->points;

I am unsure of how to fix this, please help.

I have pasted my function (sightly condensed) below.

int Code_Processor::Enter_Code(const string &username, const string &code) {
    User *user = user_iter->second;
    int points = Prizes[Codes[code]]->points;
    user->points += points;
    Codes.erase(code);
    return points;
}

I have also included part of the header file below.

class User {
  public:
     std::string username;
     std::string realname;
     int points;
     std::set <std::string> phone_numbers;
};

class Prize {
  public:
     std::string id;
     std::string description;
     int points;
     int quantity;
};

class Code_Processor {
  public:
    int Enter_Code(const std::string &username, const std::string &code);

  protected:
    std::unordered_map <std::string, User *> Names;
    std::unordered_map <std::string, User *> Phones;
    std::unordered_set <std::string> Codes;
    std::unordered_map <std::string, Prize *> Prizes;
};
Vlad from Moscow

The class template std::unordered_set does not have the subscript operator.

You could write for example

if ( Codes.find( code ) != Codes.end() )
{
    int points = Prizes[code]->points;
    user->points += points;
    Codes.erase(code);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I fix this Java notarization error?

How do I fix the error message "use of an internal package not allowed" when go getting a golang package?

What is a exception error and how do I fix it?

What is a NoReverseMatch error, and how do I fix it?

How do i fix this CopyPNG File error?

How do I fix a dimension error in TensorFlow?

How do I fix the following error?

How do I fix the error "type annotations needed" when creating a closure that uses the try operator?

How do I fix this error message "Initialization error (Eslint). Unexpected Identifier"?

How to fix 'No match for operator[]' error (c++)

how can i fix this error:These credentials do not match our records

How do I fix this ajaxToolkit error?

error:no match for ‘operator ==’,what should I do?

How do I fix this Eclipse error?

How do I fix this data type error?

How do I fix the Gparted message : Error while reading block at sector xxx?

How do I fix Python io.TextIOWrapper error message?

How do I fix the error "Result of operator '>=' is unused"

How to fix: error: no match for 'operator=' (operand types are 'Estado' and 'Estado*')

How do i fix this String formatting error

How do i fix this error message Warning: move_uploaded_file() expects parameter 1 to be string

Please how do I fix this SMTPConnectError Error?

How do I fix this Getting no reverse match error in django

How do I fix this error? java.lang.OutOfMemoryError (no error message)

How do I fix Parser Error Message: Could not load type?

How do I fix this to avoid this key error?

How do i fix mutating operator isn't mutable error?

Django Navbar No Reverse Match error - how do I fix this?

How do I fix this generic constraint error?