no match for 'operator[]'

Hello! I have this code from someone else (that I can't contact for a while)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Histos {
  private:
  map<string, TH1F*> hisNumInputStubs_;
}

void Histos::Analyze(){
  const vector<string> tnames = {"BusyOutSec", "QuietOutSec"};
  const vector<string> enames = {" in busy output sector", " in quiet output sector"};
  for (unsigned int i = 0; i <= 1; i++) {
    const string tn = tnames[i];
    const string en = enames[i];

    hisNumInputStubs_[tn]     = inputDir.make<TH1F>(("NumInputStubs"+(tn)).c_str(),     ("; No. input stubs"+(en)).c_str(),   250, -0.5, 249.5); 
}


I put the main parts of it. SO it basically declares a histogram. I need to rewrite it in a slightly different way, such that it can be integrated in a certain environment, so I have this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Histos {
  private:
  map<ObjectType, TH1F*> hisNumInputStubs_;
}
void Histos::Analyze(){
const vector<string> tnames = {"BusyOutSec", "QuietOutSec"};
    const vector<string> enames = {" in busy output sector", " in quiet output sector"};
    
    for (unsigned int i = 0; i <= 1; i++) {
        const string tn = tnames[i];
        const string en = enames[i];
        
    hisNumInputStubs_[tn].insert( pair<ObjectType, TH1F*> (BusyEvents, dirs_.at(BusyEvents).make<TH1F>(("NumInputStubs"+(tn)).c_str(), ("; No. input stubs"+(en)).c_str(),   250, -0.5, 249.5)));
        
    }
}


And I get this error: error: no match for 'operator[]' (operand types are 'std::map<TMTrackAnalyzer::ObjectType, TH1F*>' and 'const string {aka const std::basic_string<char>}')

Can someone help me? Do I need to do anything before using this []? For all the other transformation I made, where there was no [], everything works fine. Thank you!
Last edited on
Maybe check the syntax and examples of map::insert()

http://www.cplusplus.com/reference/map/map/insert/
Topic archived. No new replies allowed.