Last edited by Masterx; 05-01-2009 at 10:42 AM.
Highlight Your Codes
The Boost C++ Libraries (online Reference)
Bill Bryson"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
i came up wrtting this code , i used another map to store all of the statements ( lines) entered by user with its line number, now i can finally get rid of that stupid map element index!
anyways , when i try to compile this i get an error, i dont know why! maybe because i m trying to use a function im getting it !( proly im not doing it right)
the error im getting is :
would anyone help me correct this ?error: no match for 'operator=' in 'iter = (+InputtedLines)->std::map<_Key, _Tp, _Compare, _Alloc>::begin [with _Key = int, _Tp = std::string, _Compare = std::less<int>, _Alloc = std::allocator<std:air<const int, std::string> >]()'|
Code:#include <map> #include <string> #include <iostream> using namespace std; int main() { ~~; ~~; index = variable_location = Get_Variable_Location(StringCollector,tokenstr); return 0; }Code://in the name of God #include <map> #include <string> #include <iostream> using namespace std; int Get_Variable_Location(const map<int,string>& InputtedLines, string token) { int index = 0; map<int,string>::iterator iter; iter = InputtedLines.begin(); while ( iter != InputtedLines.end() ) { if ( (*iter).second == token ) { index = (*iter).first; } else { iter++; } } return index; }//end of function
Highlight Your Codes
The Boost C++ Libraries (online Reference)
Bill Bryson"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
What kind of error?
I don't see you including the header with the declaration of that function.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Error message:
( this indicates this line:Code:error: no match for 'operator=' in 'iter = (+InputtedLines)->std::map<_Key, _Tp, _Compare, _Alloc>::begin [with _Key = int, _Tp = std::string, _Compare = std::less<int>, _Alloc = std::allocator<std::pair<const int, std::string> >]()'|)iter = InputtedLines.begin();
and about declaration! its just pseudo main! i just forgot to add that!
the actual function is placed in a separate headerfile
so in main i have
there is a problem with function! what could be the cause?Code:#include <iostream> #include "Get_variable_index.h" int main() { ~~; ~~; index = variable_location = Get_Variable_Location(StringCollector,tokenstr); return 0; }
Highlight Your Codes
The Boost C++ Libraries (online Reference)
Bill Bryson"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
The map is passed as const reference, and so the iterator should be
Code:map<int,string>::const_iterator iter;
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Highlight Your Codes
The Boost C++ Libraries (online Reference)
Bill Bryson"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
anyone can help me get this one? why do we have to declare a const iterator when we are dealing with a const map!? why is it obligatory ?
Highlight Your Codes
The Boost C++ Libraries (online Reference)
Bill Bryson"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
The difference between const_iterator and iterator is that the first allows only read access, which makes sense if the map is const and not meant to be modified.
When the map instance is const, begin() and end() methods return a const_iterator. If the container is non-const, these methods return iterator. iterator can be implicitly converted to const_iterator (you can always assign the result of begin() and end() to a const_iterator) but not the other way round.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.