vendredi 9 septembre 2022

Char 12: error: decomposition declaration cannot be declared with type 'map'; declared type must be 'auto' or reference to 'auto'

I am learning C++ and meanwhile i have to use Hash map in c++.

This is my code:

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
 
    map<int, int> numberHash;
    vector<int> returnValue;
    for(int i=0, length = nums.size(); i<length; i++){
        int numValue = nums.at(i);
        map[numValue] = i;  
    }        
    return returnValue;
    
  }
};

What i am trying to do is put this value passed in the function as vector nums into the hashmap.

The error that i am getting is:

Char 12: error: decomposition declaration cannot be declared with type 'map'; declared 
type must be 'auto' or reference to 'auto'

the error is in line

map[numValue] = i;

can anyone please help me how and what way i can do?

Since i am learning, if there is any stupid reason please pardon me !!!

I checked the internet as well but i am not able to understand what's wrong here.

Thank you

Aucun commentaire:

Enregistrer un commentaire