C++ Boost库队列问题
我正在尝试使用boost库中的队列 当我的队列定义如下所示时,编译通过,一切正常C++ Boost库队列问题,c++,boost,C++,Boost,我正在尝试使用boost库中的队列 当我的队列定义如下所示时,编译通过,一切正常 #include <boost/lockfree/queue.hpp> #include <string> #include <iostream> boost::lockfree::queue<int> queue1(128); boost::lockfree::queue<int> queue2(128); #包括 #包括 #包括 boost::无锁
#include <boost/lockfree/queue.hpp>
#include <string>
#include <iostream>
boost::lockfree::queue<int> queue1(128);
boost::lockfree::queue<int> queue2(128);
#包括
#包括
#包括
boost::无锁::队列1(128);
boost::无锁::队列2(128);
但是,当我如下图所示更改代码(即将队列包装在结构中)时,编译失败,出现以下错误
#include <boost/lockfree/queue.hpp>
#include <string>
#include <iostream>
typedef struct stack {
int top;
boost::lockfree::queue<int> queue1(128);
boost::lockfree::queue<int> queue2(128);
} stack;
~/prgms$ g++ two_queue_to_stack.cpp
two_queue_to_stack.cpp:9:38: error: expected identifier before numeric constant
boost::lockfree::queue<int> queue1(128);
^
two_queue_to_stack.cpp:9:38: error: expected ',' or '...' before numeric constant
two_queue_to_stack.cpp:10:38: error: expected identifier before numeric constant
boost::lockfree::queue<int> queue2(128);
^
two_queue_to_stack.cpp:10:38: error: expected ',' or '...' before numeric constant
#包括
#包括
#包括
typedef结构堆栈{
int top;
boost::无锁::队列1(128);
boost::无锁::队列2(128);
}堆叠;
~/prgms$g++two_queue_to_stack.cpp
两个队列到堆栈。cpp:9:38:错误:数字常量前应有标识符
boost::无锁::队列1(128);
^
两个队列到堆栈。cpp:9:38:错误:数字常量前应为“,”或“…”
两个队列到堆栈。cpp:10:38:错误:数字常量前应包含标识符
boost::无锁::队列2(128);
^
两个队列到堆栈。cpp:10:38:错误:数字常量前应为“,”或“…”
上面的定义有什么错?我缺少一些基本的东西吗?使用:
结构堆栈{code>
int top;
boost::无锁::队列1,队列2;
//在构建堆栈期间初始化成员对象queue1和queue2
堆栈():队列1(128),队列2(128){
}
使用:
结构堆栈{code>
int top;
boost::无锁::队列1,队列2;
//在构建堆栈期间初始化成员对象queue1和queue2
堆栈():队列1(128),队列2(128){
}
struct stack {
int top;
boost::lockfree::queue<int> queue1, queue2;
// initialize the member objects, queue1, queue2, during construction of stack
stack() : queue1(128), queue2(128) {
}