'list' is used as a type, but not defined as a type.

Started by
6 comments, last by AfroFire 21 years, 1 month ago
'list' is used as a type, but not defined as a type. 'list' is used as a type, but not defined as a type. 'list' is used as a type, but not defined as a type. The error haunts me as I sleep. I already have defined that im using namespace std; The code that creates the error.
    
list<TILE *> tiles;
list<TILE *>::iterator t;

list<object *> objects;
list<object *>::iterator o;

list<TILE *> back_tiles;
list<TILE *>::iterator b;
  
I'm using GCC 3.2, and a lot of people are having problems with this, but I can't find a solution! -AfroFire [edited by - AfroFire on March 7, 2003 3:09:03 AM]
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein
Advertisement
There''s probably a variable named list in the same scope as the std::list''s you define that''s shadowing the std::list definition. Do a grep for list on your source files and see what you find.
Just yesterday I upgraded to GCC 3.2, and had that exact same problem, but for me, adding ''using namespace std;'' to the top of each of my cpp files fixed it. Make sure you have it in each file. It might make a difference.
Instead of promoting the entire STD namespace into yours, you could always do something like this:


  #include<list>using std::list;list<TITLE*> item;..etc..  


I do this in H files, since you have the possibilty of name collisions by doing a "using namespace std" in an H file as it promotes the STD namespace into the current one.

Not a big deal as the compiler/linker should warn you about it, but when making components that will be used by god knows who it is a good practice



[edited by - Tyson on March 7, 2003 1:09:03 PM]
============================A guy, some jolt, and a whole lot of code :)
quote:Tyson: I do this in H files, since you have the possibilty of name collisions by doing a "using namespace std" in an H file as it promotes the STD namespace into the current one.


You have the same possibility of name collisions by putting using... in your headers. If I include one of your headers then I will have std::whatever pulled into scope. I don''t want that but what can I do? You''re very unfriendly!

In headers the usual way is to explicitly qualify everything with its namespace eg std::list, std::vector etc.
petewood:

good point about the using declaration. I guess my point was the promoting somethign that you are going to commonly use and publicize and being part of the module you can do it my way.

Your way of course, if the better if you want to avoid collisions.

I think if you get to know me I am not as unfriendly as you think

Cheers all

A guy, some jolt, and a whole lot of code
============================A guy, some jolt, and a whole lot of code :)
Sorry Tyson - I didn''t mean you were unfriendly! I meant that forcing people to have the names pulled in wouldn''t win you any friends - metaphorically speaking.

To explicitly qualify every class with its namespace does take a bit more typing. You can easily do it though while you''re thinking what to do next.

Or you can use typedefs e.g.

typedef std::list<Monster> MonsterCont;

Use MonsterCont wherever it''s needed. This also gives you the advantage that it''s easier to change container types if you want to. Just change the typedef once and you''re laughing.

I''m sure you''re very, very friendly.

Pete
Thanks all, it works now
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein

This topic is closed to new replies.

Advertisement