void tileslist::refresh_tlist(HWND list)
{
list <stTile*>::iterator it;
SendMessage(list,LB_RESETCONTENT,0,0);
for(it=tiles.begin();it!=tiles.end();it++)
SendMessage(list,LB_ADDSTRING,0,(LPARAM)(*it)->dat.name);
}
But when I paste that same code into the other member function, it compiles perfectly...
Here are the errors for each:
MSVC++ 6:
tiles.cpp(108) : error C2059: syntax error : ''>''
tiles.cpp(108) : error C2039: ''iterator'' : is not a member of ''`global namespace''''
g++ (with cygwin):
$ g++ tiles.cpp
tiles.cpp: In member function `void tileslist::refresh_tlist(HWND__*)'':
tiles.cpp:108: parse error before `*'' token
tiles.cpp:111: `it'' undeclared (first use this function)
tiles.cpp:111: (Each undeclared identifier is reported only once for each
function it appears in.)
Thanks for help, ~SPH
🔒 Locked
Strange problem....
Advertisement
Original Post
I have a very strange problem, I copy + pasted some code from another member function of a class when I was making one, and tried to compile. Both MSVC++ 6 and g++ are giving me strange errors about it:
Yes I know iterators act like pointers:
Also I don't really care much about the stuff after the line in question (the declaration of the iterator), the problem I am having is in the declaration of the iterator.
This same code as I said works in another member function, in the same file (actually that function ends the next line above this one's beginning), and yes there is a using namespace std in there aswell.
I've been trying to get this for about an hour now, so I've thought of such things
.
Thanks for help, ~SPH
P.S. Sorry if this post seemed a bit angered... I have everlasting resent for the cowardly "Anonymous Poster"... :-D
[edited by - ShmeeBegek on September 2, 2003 4:41:05 PM]
class tileslist
{private:
list <stTile*> tiles;
int tc,stc;
public:
tileslist();
~tileslist();
bool add_tile();
bool add_subtile();
bool del_tile();
bool del_subtile();
bool edit_tile();
bool move_tile(int dir);
bool move_subtile(int dir);
void set_tilecur(int cur);
void set_subtilecur(int cur);
// Invalidates tile cursor
void refresh_tlist(HWND list);
// Invalidates subtile cursor
void refresh_stlist(HWND list);
};
Also I don't really care much about the stuff after the line in question (the declaration of the iterator), the problem I am having is in the declaration of the iterator.
This same code as I said works in another member function, in the same file (actually that function ends the next line above this one's beginning), and yes there is a using namespace std in there aswell.
I've been trying to get this for about an hour now, so I've thought of such things
Thanks for help, ~SPH
P.S. Sorry if this post seemed a bit angered... I have everlasting resent for the cowardly "Anonymous Poster"... :-D
[edited by - ShmeeBegek on September 2, 2003 4:41:05 PM]
quote:
Original post by iaretony
SendMessage(list,LB_ADDSTRING,0,(LPARAM)(*it)->dat.name);
^ should be .
Iterators act like pointers, if you de-reference them, you no longer have a pointer, you have the object you''re pointing at, and therfore, must use . notation to access "dat" member.
No. Look at the definition of the iterator:
list<stTile*>::iterator it;
Dereferencing the iterator will return a
stTile*, so using the -> operator is correct to access the object pointed to''s members. [ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
quote:
Hello ShmeeBegek,
I bet is because the * in list ::iterator it; is right next to >::
Try list ::iterator it.
Or like draqza stated your might need to put std::list ::iterator it.
Lord Bart
STL list class is a template class, it requires the template argument list, strange thing about this is that this exact line works perfectly in other member functions...
quote:
No. Look at the definition of the iterator:
list::iterator it;
Dereferencing the iterator will return a stTile*, so using the -> operator is correct to access the object pointed to''s members.
Exactly, I use iterators like this all the time
Thanks for time / help, ~SPH
I found the problem! The HWND argument''s name was list, so for some reason the compiler didn''t give an error and instead thought I was giving an HWND a template argument list.
Well anyways, the number of errors that SHOULD have produced would have been astronomical...
Thanks, ~SPH
This does not work either:
But this does:
Notice that you have a parameter named ''list'' to the function, that (and using namespace std) is the problem.
[How To Ask Questions|C++ library of container classes, algorithms and iterators. It provides many of the basic algorithms and data structures of computer science." target="_blank">STL Programmer''s Guide|C++ Style and Technique FAQ - Designer and implementor the C++ programming language." target="_blank">Bjarne FAQ|C++ FAQ Lite - Frequently Asked Questions about the C++ language." target="_blank">C++ FAQ Lite|C++ Reference - The standard C++ library is a collection of functions, constants, classes and objects that extends the C++ language providing basic functionality to interact with the operating system and some standard classes, objects and algorithms that may be commonly needed." target="_blank">C++ Reference|MSDN]
#include <list>
using namespace std;
void foo(int list)
{
list<int> bar;
}
But this does:
#include <list>
void foo(int list)
{
std::list<int> bar;
}
Notice that you have a parameter named ''list'' to the function, that (and using namespace std) is the problem.
[How To Ask Questions|C++ library of container classes, algorithms and iterators. It provides many of the basic algorithms and data structures of computer science." target="_blank">STL Programmer''s Guide|C++ Style and Technique FAQ - Designer and implementor the C++ programming language." target="_blank">Bjarne FAQ|C++ FAQ Lite - Frequently Asked Questions about the C++ language." target="_blank">C++ FAQ Lite|C++ Reference - The standard C++ library is a collection of functions, constants, classes and objects that extends the C++ language providing basic functionality to interact with the operating system and some standard classes, objects and algorithms that may be commonly needed." target="_blank">C++ Reference|MSDN]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement