expected unqualified-id before 'for'

Hello! I have this code (I put just a part of it):

1
2
3
4
5
6
7
8
9
  class TMTrackAnalyzer : public edm::EDAnalyzer {
    public:
      # declare public stuff here
    private:
      # declare private stuff here
      for(int i=1;i<=10;i++){
        cout<<i;
      }
  };


And I get this error:
expected unqualified-id before 'for'
for(int i=1;i<=10;i++){

What do I do wrong? Thank you!
The code needs to go into a method:
1
2
3
4
5
6
7
8
9
10
11
  class TMTrackAnalyzer : public edm::EDAnalyzer {
    public:
      # declare public stuff here
    private:
      void f() {
        # declare private stuff here
        for(int i=1;i<=10;i++){
          cout<<i;
        }
      }
  };
But in that for loop I want to declare some private members of the class. Where do I need to call that method later?
But in that for loop I want to declare some private members of the class

If you declare variables within the loop, they're not private members of the class. They're local to the scope of the loop. Given the code kbw posted, you have four different places you can declare variables.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class TMTrackAnalyzer : public edm::EDAnalyzer 
{
public:
    // 1. Declare public stuff here 
private:
      // 2. Declare private stuff here 
      void f() 
     {  // 3. Declare variables local to f() here
         for (int i=1; i<=10; i++)
        {  // 4. Declare variables local to the scope of the loop here
            cout<<i;
        }
     }
};


Where do I need to call that method later?

Where ever you want to output the numbers 1-10, which is what f() does.
Last edited on
I understand, but what I want is to declare private member of the class (no just of the loop), but they have a similar name:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
for (unsigned int i = 0; i <= 75; i++) {                                                                                                
    const string tn = tnames[i];                                                                                                         
    const string en = enames[i];                                                                                                         
                                                                                                                                         
    map< ObjectType, TH1F*> hisNumInputStubs_[tn] ;                                                                                      
    map< ObjectType, TH1F*> hisQoverPtInputStubs_[tn];                                                                                   
    map< ObjectType, TH1F*> hisNumOutputStubs_[tn];                                                                                      
    map< ObjectType, TH1F*> hisNumStubsPerTrack_[tn];                                                                                    
    map< ObjectType, TH1F*> hisTrackQoverPt_[tn];                                                                                        
    map< ObjectType, TH1F*> hisTrackPurity_[tn];                                                                                         
    map< ObjectType, TH1F*> hisNumTPphysics_[tn];                                                                                        
    map< ObjectType, TH1F*> hisNumTPpileup_[tn];                                                                                         
    map< ObjectType, TH1F*> hisSumPtTPphysics_[tn];                                                                                      
    map< ObjectType, TH1F*> hisSumPtTPpileup_[tn];                                                                                       
  }


This is what I actually have. So how can I declare all these, without writing them one by one? Thank you!
I don't understand you
¿what's the purpose of the loop?


> map< ObjectType, TH1F*> hisNumInputStubs_[tn];
first, that's an array declaration, so the brackets would set the size of the array.
but `tn' is an string, not a number.

If you wanted to populate the map (with value nullptr), there should be no type before.
However, the key of your map is an `Objectype', not a string.


To describe your problem better, please read this
https://blog.codinghorror.com/rubber-duck-problem-solving/
Topic archived. No new replies allowed.