Go Down

Topic: Inserting Struct into queue list (Read 1 time) previous topic - next topic

fnsnoop

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.

Arrch


PaulS

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.

fnsnoop

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.

PeterH

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.
I only provide help via the forum - please do not contact me for private consultancy.

WizenedEE


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.

RWSDev

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
Come see what we're doing: http://rwsdev.net

PaulS

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?

RWSDev

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: [Select]

// 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.

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

PaulS

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.

Go Up