Skip to main content
gamedev.net
🔒 Locked

Strange problem....

Started by ShmeeBegek Sep 2, 2003 at 3:12 PM 8 replies 450+ views
Original Post
ShmeeBegek
ShmeeBegek
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++)
		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
AIM ME: aGaBoOgAmOnGeR
draqza
draqza
"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.
WNDCLASSEX Reality;......Reality.lpfnWndProc=ComputerGames;......RegisterClassEx(&Reality);Unable to register Reality...what's wrong?---------Dan Uptonhttp://0to1.orghttp://www20.brinkster.com/draqza
iaretony
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.

Tony
ShmeeBegek
ShmeeBegek
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]
AIM ME: aGaBoOgAmOnGeR
Lord Bart
Lord Bart
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
Lektrix
Lektrix
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 ]
ShmeeBegek
ShmeeBegek

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

AIM ME: aGaBoOgAmOnGeR
ShmeeBegek
ShmeeBegek

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
AIM ME: aGaBoOgAmOnGeR

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.