I have defined a dynamic memory as * indexs (vector of vector) to store set of values. Then, I appended this memory. Afterthat, I want to get a print of these values. For that I am using another function as follows. For that function, I am calling above values by references. I don’t know proper way to use iterator to print those values.
Here is my piece of codes and the error I got for that.
vector< vector<unsigned int> >* indexs = new vector< vector<unsigned int> >(9);
for( ){ //finish data adding into indexs }
calcParameter(*indexs); //call function
void myclass::calcParameter(vector< vector<unsigned int> >const &indexs){
vector< vector<unsigned int> > :: iterator cell_i;
for (cell_i=indexs->begin(); cell_i != indexs->end();cell_i++){ //this is line 305 in my program
vector<unsigned int> :: iterator pij;
for (pij=cell_i->begin(); pij =! cell_i->end(); pij++){
cout<<" "<<*pij;
}
cout<<endl;
}
}
error message: 305-base operand of `->' has non-pointer type `const
std::vector<std::vector<unsigned int, std::allocator<unsigned int> >,
std::allocator<std::vector<unsigned int, std::allocator<unsigned int> > > >'
when I use simple for loop to get that, It works but I want to learn how to use iterator for this.
void myclass::calcParameter(vector< vector<unsigned int> >const &indexs){
for (int i=0; i<indexs.size(); i++){
for (int j=0; j< indexs[i].size(); j++){
cout<<" "<<indexs[i][j];
}
cout<<endl;
}
}
Any help please..
indexsis not a pointer, it’s a reference, that’s all. You need to sayand not
(etc).