i have had a problem with /usr/include/c++/4.6/ext/new_allocator.h:108:9: error: use of deleted function ‘SMIBQueue::SMIBQueue(const SMIBQueue&)’
with C++ eclipse.
and i am using -std=c++0x
flag to use C++11
though i found the point that the error occur at, i don't know why.
this is header file
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);
};
and this is the function that the error occur at
std::vector<SMIBQueue> SMIBQueues::smibQueues;
void SMIBQueues::queueInit(int numOfClient){
for(int i = 0 ; i < numOfClient; i++){
SMIBQueue s;
smibQueues.push_back(s);
}
}
in this function, push_pack method makes the error. when i eliminate the part, there is no problem while compiling.
std::mutex
has a deleted copy-constructor, this means that SMIBQueue
will have its copy-constructor implicitly deleted since the compiler cannot generate one for you.
How would it go about copying a class which has members that cannot be copied? You will explicitly need to define your own copy-constructor if you want SMIBQueue
to be copyable.
WHERE DOES MY CODE REQUIRE A COPY TO BE MADE?
When you are calling smibQueues.push_back (s)
a copy of s
will be stored inside smibQueues
, which requires (the implicitly deleted) copy-constructor.
You can circumvent this specific problem by using smibQueues.emplace_back ()
to default-construct a SMIBQueue
directly inside your smibQueues
(ie. std::vector
).
Note: Just keeo in mind that smibQueues
might require SMBIQueue
to be copyable/movable during other operations, such as if it tries to resize the underlying buffer, etc.
RECOMMENDED SOLUTION
Define your own copy-constructor if you plan to use it in contexts which require copying, but do keep in mind that std::mutex
is neither copyable or movable, according to the Standard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With