Pages: [1]   Go Down
Author Topic: Inserting Struct into queue list  (Read 1002 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using the queue list library from the playground http://arduino.cc/playground/Code/QueueList i have a struct datatype and would like to insert it into it but its giving me an error.

This is what I want to do
QueueList <struct> queue;

error: template argument 1 is invalid
error: invalid type in declaration before ';' token

Is there a better way to approach to linking structs in a list.
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post the rest of your code.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49083
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am using the queue list library from the playground http://arduino.cc/playground/Code/QueueList i have a struct datatype and would like to insert it into it but its giving me an error.
You have a struct with some name. The struct keyword and the struct name need to be in the <>, not just the struct keyword.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, worked like a charm!  I am assuming the reason for this is because each struct is a unique object, therefore the specific struct needs to be called.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Each struct is a specific type. To refer to that type you use 'struct' followed by the name of your struct.

It is common to use a typedef  so that you can refer to that struct type without having to use the struct keyword; this is only a bit of syntactic sugar but means your struct behaves syntactically just like any of the basic types.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is common to use a typedef  so that you can refer to that struct type without having to use the struct keyword; this is only a bit of syntactic sugar but means your struct behaves syntactically just like any of the basic types.

... which is not necessary in C++, which arduino uses.
Logged

Minnesota
Offline Offline
Newbie
*
Karma: 1
Posts: 15
Living each day byte by byte
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I know this thread is old but if anyone can share an example of using a struct with QueueList I would really appreciate it.

I'm not sure how to create the member of the struct and add it to the queue.

Thanks in advance.

JB
Logged

Come see what we're doing: http://rwsdev.net

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49083
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm not sure how to create the member of the struct and add it to the queue.
Do you mean that you do not know how to create an instance of a struct?

What does the definition of your struct look like?
Logged

Minnesota
Offline Offline
Newbie
*
Karma: 1
Posts: 15
Living each day byte by byte
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually what I meant was how do I put my struct into the queue as a list entry or member using this library...

alternatively I decided to not go with the library and just use a standard linked list that contains my struct ... as this:

Code:
// device and linked list structure
struct linkedList {
  int id;
  char *name;
  struct dev{
    int hash;
    unsigned long ts;
  }dev;
  struct linkedList *next;
}start, *node; 

For some reason I was thinking that using this library would allow me to directly access the Nth element of the list/queue, however I think I was mistaken, hence my alternative approach since I have to traverse the list either way, less overhead not using the library.

Logged

Come see what we're doing: http://rwsdev.net

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49083
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
For some reason I was thinking that using this library would allow me to directly access the Nth element of the list/queue, however I think I was mistaken
You can access the nth element of a list, but not the nth element of a queue. A queue is like a line of people waiting to buy tickets to a soccer match. Which person in line should be dealt with next? The first person, obviously. Where should people get in line? At the end, of course.

I don't see the advantage of a struct in a struct.
Logged

Pages: [1]   Go Up
Jump to: