我想在该块内的 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;
}
问题出在其他部分,如果阻止即。迭代 list1 和list1.size(); ..