error expected primary expression before

0

I get an error that I do not understand when compiling a code, this is the code: (the function is private)

void  gr_simplificada::erase_epsilon(set<char> h){
        set<produccion>::iterator it;
        set<char>::iterator itset;
        for(itset=h.begin();itset!=h.end();itset++){
            for(it=gr_simplificada.producciones_.begin();it!=gr_simplificada.producciones_.end();it++){
                if((*itset)==((*it).get_noterminales())){
                    for(int k =0 ;k<(*it).get_regla().size();k++){
                        for(int q=0; q<(*it).get_regla()[k].size();q++){
                            char objetivo = (*it).get_regla()[k][q];
                            if(objetivo=="~"){
                                (*it).get_regla().erase(k);
                            }
                        }
                    }
                }
            }
        }
    }

This is the error that I do not understand:

GR_SIMPLIFICADA.cpp:196:35: error: expected primary-expression before ‘.’ token
             for(it=gr_simplificada.producciones_.begin();it!=gr_simplificada.producciones_.end();it++){
                                   ^
GR_SIMPLIFICADA.cpp:196:77: error: expected primary-expression before ‘.’ token
             for(it=gr_simplificada.producciones_.begin();it!=gr_simplificada.producciones_.end();it++){

The function eliminates forms part of an algorithm of elimination of empty productions of a grammar independent of the context

GRacias

    
asked by AER 13.11.2017 в 11:59
source

1 answer

2

So I see gr_simplificada is a type, but you're using the name of the object as an instance. Since you are in a member method, you do not need to prepend anything to access member variables:

//    vvvvvvvvvvvvvvv <-- esto es el tipo!
void  gr_simplificada::erase_epsilon(set<char> h){
    set<produccion>::iterator it;
    set<char>::iterator itset;
    for(itset=h.begin();itset!=h.end();itset++){
        for(it=/*gr_simplificada.*/producciones_.begin();it!=/*gr_simplificada.*/producciones_.end();it++){
//             ~~~~~~~~~~~~~~~~~~~~    <-- innecesario -->   ~~~~~~~~~~~~~~~~~~~~
            if((*itset)==((*it).get_noterminales())){
                for(int k =0 ;k<(*it).get_regla().size();k++){
                    for(int q=0; q<(*it).get_regla()[k].size();q++){
                        char objetivo = (*it).get_regla()[k][q];
                        if(objetivo=="~"){
                            (*it).get_regla().erase(k);
                        }
                    }
                }
            }
        }
    }
}
    
answered by 13.11.2017 / 12:14
source