gpt4 book ai didi

c++ - 如何 spsc_queue.pop() 这个结构?

转载 作者:行者123 更新时间:2023-11-28 03:09:47 24 4
gpt4 key购买 nike

我正在尝试 spsc_queue.pop() 这个结构

enum action_type {
SUBSCRIBE,
UNSUBSCRIBE,
MESSAGE
};

struct action {
action() = default ;
action(action_type t, connection_hdl h) : type(t), hdl(h) {}
action(action_type t, server::message_ptr m) : type(t), msg(m) {}

action_type type;
websocketpp::connection_hdl hdl;
server::message_ptr msg;
};

action a;
while(m_actions.pop(a)){
...

但是每当我测试

std::cout << "'" << a.type << "'" << std::endl;

'0' 被写入终端,但它应该只是action_type 的值之一。我读过 struct 的默认值是 0,但是为什么 spsc_queue.pop() 不能设置 a?

( boost::lockfree::spsc_queue )

最佳答案

SUBSCRIBE 的值 0。如果您想给 SUBSCRIBE 一个不同的值,您可以初始化枚举器,例如,使用 1:

enum action_type {
SUBSCRIBE = 1,
UNSUBSCRIBE,
MESSAGE
};

其他枚举器将获得相应的下一个整数值。

关于c++ - 如何 spsc_queue.pop() 这个结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18797140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com