iterator & operator overloading error
-
This isn't the problem you are asking about, but shouldn't your operator >> and operator << be using the stream passed to it as an argument instead of using cin/cout?
if you mean this yet the same error: friend istream &operator >> (istream &is,const code_ch &C){ is>>C.number>>C.ch; return is; } friend ostream &operator << (ostream &os,const code_ch &C){ os<<C.ch<<" number="<<C.number; return os; } or :
`friend istream &operator >> (istream &is,const code_ch &C){ return is>>C.number>>C.ch; //return is; } friend ostream &operator << (ostream &os,const code_ch &C){ return os<<C.ch<<" number="<<C.number; //return os; }`
-
if you mean this yet the same error: friend istream &operator >> (istream &is,const code_ch &C){ is>>C.number>>C.ch; return is; } friend ostream &operator << (ostream &os,const code_ch &C){ os<<C.ch<<" number="<<C.number; return os; } or :
`friend istream &operator >> (istream &is,const code_ch &C){ return is>>C.number>>C.ch; //return is; } friend ostream &operator << (ostream &os,const code_ch &C){ return os<<C.ch<<" number="<<C.number; //return os; }`
Yes, that is what I was meant. As I said, it wasn't the problem that you were asking about, so it doesn't surprise me that it gives you the same error message. It was still a problem. I just spotted something.
khomeyni wrote:
friend istream &operator >> ( istream &is, const code_ch &C )
{
is >> C.number >> C.ch;
return is;
}This function changes the code_ch object passed to it. So the parameter can not be const.
-
Yes, that is what I was meant. As I said, it wasn't the problem that you were asking about, so it doesn't surprise me that it gives you the same error message. It was still a problem. I just spotted something.
khomeyni wrote:
friend istream &operator >> ( istream &is, const code_ch &C )
{
is >> C.number >> C.ch;
return is;
}This function changes the code_ch object passed to it. So the parameter can not be const.
ok thanks it solve my first problem but yet: [sajad@sajad Desktop]$ g++ c++file.cpp c++file.cpp: In function ‘int main(int, char**)’: c++file.cpp:66: error: ‘struct std::_List_iterator<code_ch>’ has no member named ‘begin’ c++file.cpp:66: error: ‘struct std::_List_iterator<code_ch>’ has no member named ‘end’
-
ok thanks it solve my first problem but yet: [sajad@sajad Desktop]$ g++ c++file.cpp c++file.cpp: In function ‘int main(int, char**)’: c++file.cpp:66: error: ‘struct std::_List_iterator<code_ch>’ has no member named ‘begin’ c++file.cpp:66: error: ‘struct std::_List_iterator<code_ch>’ has no member named ‘end’
oh sorry ,it is a part of huge program so i only copy it and no member is in the list.but when i fix it and add: for(int i=0;i<10;i++){ code_ch *h=new code_ch; h->number=i; h->ch='1'; w.push_front(*h); } or : code_ch H; H.number=10; H.ch='k'; w.push_front(H); yet the same problem.
-
ok thanks it solve my first problem but yet: [sajad@sajad Desktop]$ g++ c++file.cpp c++file.cpp: In function ‘int main(int, char**)’: c++file.cpp:66: error: ‘struct std::_List_iterator<code_ch>’ has no member named ‘begin’ c++file.cpp:66: error: ‘struct std::_List_iterator<code_ch>’ has no member named ‘end’
True, you still have this problem. Why don't you take a closer look at it.
khomeyni wrote:
int main(int argc,char **argv)
{
if(argc==1)
{
cout<<"you haven't entered a file! exiting..."<<endl;
return 1;
}
list<code_ch>w;
int *a=new int [200];//for saving the number of each ch
for(int i=0;i<200;i++)
a[i]=0;list<code\_ch>::iterator l=w.begin(); cout<<"the list is:"<<endl; copy(l.begin(),l.end(),ostream\_iterator<code\_ch>(cout," "));
}
; And your error message was:
khomeyni wrote:
c++file.cpp: In function ‘int main(int, char**)’: c++file.cpp:66: error: ‘struct std::_List_iterator’ has no member named ‘begin’ c++file.cpp:66: error: ‘struct std::_List_iterator’ has no member named ‘end’
That says that your iterator does not have a begin or end member. It is right, iterators don't. What does have a begin and end? What is it that you want to be copying from? You should be able to get it from here.
-
True, you still have this problem. Why don't you take a closer look at it.
khomeyni wrote:
int main(int argc,char **argv)
{
if(argc==1)
{
cout<<"you haven't entered a file! exiting..."<<endl;
return 1;
}
list<code_ch>w;
int *a=new int [200];//for saving the number of each ch
for(int i=0;i<200;i++)
a[i]=0;list<code\_ch>::iterator l=w.begin(); cout<<"the list is:"<<endl; copy(l.begin(),l.end(),ostream\_iterator<code\_ch>(cout," "));
}
; And your error message was:
khomeyni wrote:
c++file.cpp: In function ‘int main(int, char**)’: c++file.cpp:66: error: ‘struct std::_List_iterator’ has no member named ‘begin’ c++file.cpp:66: error: ‘struct std::_List_iterator’ has no member named ‘end’
That says that your iterator does not have a begin or end member. It is right, iterators don't. What does have a begin and end? What is it that you want to be copying from? You should be able to get it from here.
-
if you mean this? adding this in the main: for(int i=0;i<10;i++){ code_ch *h=new code_ch; h->number=i; h->ch='1'; w.push_front(*h); } or : code_ch H; H.number=10; H.ch='k'; w.push_front(H); yet the same problem.
No, I don't mean that. Play closer attention to the error message and the line it is referring to. It is telling you what the problem is and where it is. Go over each part of that line and look for a difference between what you intended and what you wrote.
-
No, I don't mean that. Play closer attention to the error message and the line it is referring to. It is telling you what the problem is and where it is. Go over each part of that line and look for a difference between what you intended and what you wrote.
i can not understand: even for this does not work: list<int> PL; PL.push_front(100); list<int>::iterator p=PL.begin(); copy(p.begin(),p.end(),ostream_iterator<int>(cout," ")); cout<<endl; while in another where i wrote: list<code_ch>::iterator p=t.begin(); int i=0; while(p!=t.end()){ heap[i]=*p; p++; i++; heapsize++; } //part of a program and correctly works. does list has not such ability to iterate over list elements as i want to do?
-
i can not understand: even for this does not work: list<int> PL; PL.push_front(100); list<int>::iterator p=PL.begin(); copy(p.begin(),p.end(),ostream_iterator<int>(cout," ")); cout<<endl; while in another where i wrote: list<code_ch>::iterator p=t.begin(); int i=0; while(p!=t.end()){ heap[i]=*p; p++; i++; heapsize++; } //part of a program and correctly works. does list has not such ability to iterate over list elements as i want to do?
-
ok i must write: copy(x.begin(),w.end(),ostr.....) very simple error and stupidly error !!! thanks.
Good. You got it. Though of course its: copy(w.begin(),w.end(),ostr.....)