使用已删除的函数出错
use of deleted function error
我有一个问题,/usr/include/c++/4.6/ext/new_allocator.h:108:9: error: use of deleted function ‘SMIBQueue::SMIBQueue(const SMIBQueue&)’
与c++ eclipse。
和我使用-std=c++0x
标志使用c++ 11
虽然我找到了错误发生的地方,但我不知道为什么。
这是头文件
class SMIBQueue{
private:
std::queue<unsigned char> exceptionQueue;
std::queue<UserRequest*> userInputQueue;
std::queue<LpRsp*> lpRspQueue;
std::queue<LpCmd*> lpCmdQueue;
std::mutex EvtQueueLock;
std::mutex UserQueueLock;
std::mutex LpRspQueueLock;
std::mutex LpCmdQueueLock;
public:
int evtGetItem(unsigned char &item);
int evtPutItem(unsigned char item);
int userGetItem(UserRequest*& item);
int userPutItem(UserRequest* item);
int lpGetItem(LpCmd*& queue_buf);
int lpPutItem(LpCmd *queue_buf);
int lpRspGetItem(LpRsp*& queue_buf);
int lpRspPutItem(LpRsp *queue_buf);
int lpRemoveQueuedInfo();
int lpRspRemoveQueuedInfo();
};
class SMIBQueues{
public:
static std::vector<SMIBQueue> smibQueues;
static void queueInit(int numOfClient);
static int evtGetItem(int sasAddr, unsigned char &item);
static int evtPutItem(int sasAddr, unsigned char item);
static int userGetItem(int sasAddr, UserRequest*& item);
static int userPutItem(int sasAddr, UserRequest* item);
static int lpGetItem(int sasAddr, LpCmd*& queue_buf);
static int lpPutItem(int sasAddr, LpCmd *queue_buf);
static int lpRspGetItem(int sasAddr, LpRsp*& queue_buf);
static int lpRspPutItem(int sasAddr, LpRsp *queue_buf);
static int lpRemoveQueuedInfo(int sasAddr);
static int lpRspRemoveQueuedInfo(int sasAddr);
};
,这是错误发生在
的函数std::vector<SMIBQueue> SMIBQueues::smibQueues;
void SMIBQueues::queueInit(int numOfClient){
for(int i = 0 ; i < numOfClient; i++){
SMIBQueue s;
smibQueues.push_back(s);
}
}
在这个函数中,push_pack方法产生错误。当我删除这部分时,编译时就没有问题了。
std::mutex
已经删除了复制构造函数,这意味着SMIBQueue
将隐式删除其复制构造函数,因为编译器不能为您生成一个。
如果一个类的成员不能被复制,它将如何去复制呢?如果您希望SMIBQueue
可复制,则需要显式地定义自己的复制构造函数。
我的代码需要在哪里做一个副本?
调用smibQueues.push_back (s)
时,s
的副本将存储在smibQueues
中,这需要(隐式删除)复制构造函数。
您可以通过使用smibQueues.emplace_back ()
来默认构造直接在smibQueues
中构建SMIBQueue
来绕过这个特定的问题。std::vector
)。
注意:请记住,smibQueues
可能要求SMBIQueue
在其他操作期间是可复制/可移动的,例如当它试图调整底层缓冲区的大小时,等等。
推荐解决方案
定义你自己的复制构造函数如果你计划在需要复制的上下文中使用它,但要记住,根据标准,std::mutex
既不可复制也不可移动。
- 类中私有结构的构造函数出错
- 字符串验证函数出错
- 我的类默认构造函数出错
- Dev-C++和Code::Blocks中的析构函数出错
- int对的哈希函数出错
- MSVC 编译器错误导致迭代器和友元函数出错
- 复制构造函数出错
- 使用 WinSock2 开发,使用 CreateThread() 函数出错
- 链接列表的Push_back函数出错
- 结构初始化中的隐式复制构造函数出错
- 异步函数出错
- 编译器错误消息错误:令牌之前的预期')' '*'。我的构造函数出错
- c++中使用std::bind和std::函数出错
- 在vector排序中使用c++模板函数出错
- 使用std::for_each lambda函数出错
- 二叉搜索树插入函数出错
- 调用类的函数出错
- c++使用删除函数出错
- 使用已删除的函数出错
- 调用构造函数出错