#### Archived

This topic is now archived and is closed to further replies.

# Strange problem....

## Recommended Posts

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:
void tileslist::refresh_tlist(HWND list)
{
list <stTile*>::iterator it;
SendMessage(list,LB_RESETCONTENT,0,0);

for(it=tiles.begin();it!=tiles.end();it++)
}

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

##### Share on other sites
Really strange, isn''t it?

http://www.catb.org/~esr/faqs/smart-questions.html#bespecific

##### Share on other sites
"Iterator is not a member of global namespace"

-- did you try putting a using namespace std; line in?

Also, if you would post the other function in which it works correctly, it might be easier to find the error.

##### Share on other sites
^ 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.

Tony

##### Share on other sites
Yes I know iterators act like pointers:

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]

##### Share on other sites
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

##### Share on other sites
quote:
Original post by iaretony
^ 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 ]

##### Share on other sites

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

##### Share on other sites

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

##### Share on other sites
This does not work either:
#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|STL Programmer''s Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]

• ### Forum Statistics

• Total Topics
628333
• Total Posts
2982139

• 9
• 24
• 9
• 9
• 13