模板类中使用了错误的构造函数

wrong constructor used in template class

本文关键字:错误 构造函数      更新时间:2023-10-16

我需要在我的模板类中使用boost::interprocess::mutex在函数中,我在下面声明了变量

  named_mutex mutex(open_only, m_name.c_str() 
  ,permissions(0666));

我不知道为什么我不能编译,我得到一个错误下面。编译器如何可能不使用正确的构造函数(它试图匹配具有const引用的构造函数)以及如何强制使用正确的构造函数?

    error: no matching function for call to   
    boost::interprocess::named_mutex::named_mutex(const 
    boost::interprocess::open_only_t&,   const char*, boost::interprocess::permissions)’
    /usr/local/include/boost/interprocess/sync/named_mutex.hpp:140: note: 
    candidates are: 
    boost::interprocess::named_mutex::named_mutex(boost::interprocess::open_only_t, const char*)

接受open_only_t的构造函数不接受权限参数。这真的没有意义-你试图打开一个现有的互斥锁,而不是创建一个。

删除权限,它应该找到适当的过载