我正在尝试 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
?
最佳答案
SUBSCRIBE
的值是 0
。如果您想给 SUBSCRIBE
一个不同的值,您可以初始化枚举器,例如,使用 1
:
enum action_type {
SUBSCRIBE = 1,
UNSUBSCRIBE,
MESSAGE
};
其他枚举器将获得相应的下一个整数值。
关于c++ - 如何 spsc_queue.pop() 这个结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18797140/