c++ - 如何通过对象引用传递函数的参数(C++)

标签 c++ object boost reference

我想通过对象引用传递函数的参数。如果我这样写代码:

#include <boost\thread\thread.hpp>
class Data 
{
public:
    Data();
    ~Data();
    void func(boost::mutex  &mut);
private:

    boost::condition_variable   condData;
    boost::mutex                mutData;
};


void Data::func(boost::mutex  &mut)
{
    Data* data = this;
    data->mutData = mut;// Here a syntax error
}

这里data->mutData = mut;显示错误

错误:等号上的“boost::mutex &boost::mutex:.Operator=(boost::mutex &)”无法访问

如何解决这个问题?

最佳答案

根据设计,无法复制或分配互斥量。

允许这样做会使使用互斥体保护某些资源的想法失效。如果每个人都有自己的互斥锁拷贝,共享资源就不再是单一的锁。

关于c++ - 如何通过对象引用传递函数的参数(C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32114206/

相关文章:

javascript - 对象和 console.log 的奇怪行为

oracle - 管理 Oracle 同义词

c++ - 访问持有 QString 的 shared_ptr 时程序崩溃

javascript - alert() 整个多维对象

c++ - boost 异步读/写失败, "Insufficient system resources exist to complete the requested service"

c++ - boost::pool 实内存分配

c++ - 在 VS Code 上使用 Boost

c++ - 包含在 std::regex 搜索中,使用 std::regex_token_iterator 从 std::sub_match 中排除

c++ - WinSock2:使用 recv 和 send 在单独的线程中处理接受的传入连接

c++ - 我可以用正则表达式做到这一点吗?