這是我的問題。試圖引用已刪除的函數,具有互斥成員的結構
我有這樣的結構。
struct threadInfo
{
std::condition_variable cv;
std::mutex m;
int priorityLevel;
};
當建立我的代碼,我得到這個錯誤
錯誤C2280
threadInfo::threadInfo(const threadInfo &)
:嘗試 引用刪除的功能PriorityListMutex
從我的理解這意味着threadInfo
構造是所謂的,它試圖複製mutex
這是不可能的。
我對C++沒有多少經驗,即使我有點理解發生了什麼,我不知道如何嘗試解決這個問題。任何幫助將是偉大的!
下面是一個使用ThreadInfo的
threadInfo info;
info.priorityLevel = priority;
priorityListMutex.lock();
for (std::list<threadInfo>::iterator it = threadList.begin(); it != threadList.end(); it++)
{
if ((*it).priorityLevel < info.priorityLevel)
{
threadList.insert(it, info);
break;
}
else if (it == threadList.end())
{
threadList.push_back(info);
break;
}
}
priorityListMutex.unlock();
std::unique_lock<std::mutex> lock(info.m);
info.cv.wait(lock);
我猜結構正在某處存在複製的代碼,但我完全缺少的地方。
請發佈[MCVE] – Rama
不要複製結構? ('condition_variable'和'mutex'都將它們的拷貝標記爲刪除) – Borgleader
添加了正在使用結構的代碼示例。 – lhbortho