max0x7ba / atomic_queue

C++ lockless queue.
MIT License
1.47k stars 176 forks source link

how to put struct to queue #48

Closed chansonZ closed 1 year ago

chansonZ commented 1 year ago

Can anyone help?

typedef struct {
    int a;
    char b[32];
} UserData;

compile error when:

constexpr unsigned CAPACITY = 1024;
AtomicQueue<UserData, CAPACITY> q; 
max0x7ba commented 1 year ago

When you report problems, you should provide a complete reproducible example with the error message, so that no guesswork or undue effort is required to help you.


Your code doesn't compile because you use queue template AtomicQueue designed for atomic elements, whereas UserData isn't one.

Queue template AtomicQueue2, on the other hand, is designed for non-atomic elements and that is what you should use:

AtomicQueue2<UserData, CAPACITY> q;

You should always read documentation before using something or asking questions. 15 minutes spent on reading documentation saves you endless hours of debugging.