Jump to content
  • Advertisement
Sign in to follow this  
SpookySprite

errors with linked list

This topic is 4406 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to create a linked list in one of my programs but i'm getting errors i don't know how to fix. I guess the main problem is that i don't understand linked lists to well but it would be much appretiated if someone could help solve the problems. here's the code: typedef struct Clears *pClears; typedef struct Clears { int time; int squareX1; int squareX2; int squareY1; int squareY2; struct pClears *next; }; struct Clears Head; Head->next = NULL; and the error messages: conflicting types for `struct ClearsPtr' previous declaration as `typedef struct Clears*ClearsPtr' syntax error before `->' token I'm not sure if it's important but i'm using Dev-C++.

Share this post


Link to post
Share on other sites
Advertisement
Ok, so I ran it through Visual C++ Express and I ended up with a couple of somewhat different errors, but maybe it's a little more forgiving. The errors that it found are

In the code block "typedef struct Clears { ... };" you aren't declaring the new type. i.e., there should be a typename after the '}' and before the ';', so for example in C you'd do something like


typedef struct Clears
{
int time;

int squareX1;
int squareX2;
int squareY1;
int squareY2;

struct pClears *next;
} Clears;




But you're using C++, so there's no need to use a typedef like that, you should just use something like:


struct Clears
{
int time;

int squareX1;
int squareX2;
int squareY1;
int squareY2;

Clears* next;
};




The other thing that it caught was 'Head->next = NULL;'. This statement would be valid if 'Head' were a pointer to a Clears, but it's not a pointer, so you need to use 'Head.next = NULL;'.

I'm not sure what the conflicting types error message was all about though.

[Edited by - blarn on November 17, 2006 1:59:41 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by blarn
But you're using C++, so there's no need to make your own linked list like that, you should just use something like:



struct Clears {
int time;

int squareX1;
int squareX2;
int squareY1;
int squareY2;
};

// somewhere else
std::list<Clears> the_clears;
// Or std::deque, or std::vector... why do you think you need a linked list,
// anyway? Did you ever even get taught that there are other ways of
// implementing a resizable, sequential container?




Fixed.

Share this post


Link to post
Share on other sites
ok so are there still any unsolved bugs? I was going to answer this but I think zahlman covered it all. -> is a pointer operator, you cant use it on objects.

Share this post


Link to post
Share on other sites
Now i'm just getting "syntax error before `.' token" when i changed Head->next to Head.next. I'm just going to use a vector though, it seems to be alot easier. Thanks for the help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!