-2

そのブロック内の list2 の後に list1 を繰り返し処理したいと思います。それを実現する方法を教えてください。それが機能しない理由は推測できますが、それを実現する方法がわかりません

enum type {VALID,INVALID};
#define ADD_A(x,y) addtolist x(#x,VALID,y);
#define ADD_B(x,y) addtolist x(#x,INVALID,y);
class addtolist {
  public:
    std::string name;
    int val;
    std::list<int> list1;
    std::list<int> list2;
    std::list<int>::iterator v;
    std::list<int>::iterator w;
    addtolist(std::string name, type _val, int range);
};

class newlist {
  public:
    newlist(){
    ADD_A(ob1,5);
    ADD_B(ob2,5);
    }
};

addtolist::addtolist( std::string name, type _val,  int range ) {
    name = name;
    val = _val;
    int i;
    if (val==0){
        for(i=0;i<=range;i++){
            list1.push_back(i);
        }
        for (v = list1.begin(); v != list1.end(); ++v){
            std::cout <<"\nvalid list == "<<*v << std::endl;
        }
        std::cout<<"\n size of list1 == "<< list1.size()<<std::endl;
    }else if (val==1){
       for(i=0;i<=range;i++){
           list2.push_back(i);
       }
   for ( w = list2.begin(); w != list2.end(); ++w){
           std::cout <<"\nINVALID LIST == "<<*w<< std::endl;
       }
// i dont know why this gets zero and also the loop does not work and how to make this work
       std::cout<<"\n THIS BECOMES ZERO == "<< list1.size()<<std::endl;
       for (v = list1.begin(); v != list1.end(); ++v){
           std::cout <<"\nVALID LIST == "<<*v << std::endl;
       }
    }
}

int main()
{
    newlist a;
}

問題は、else if block ie の部分にあります。list1 とlist1.size() を繰り返します。..

4

1 に答える 1