构造非初始化结构时的"error: no matching function for call to"
"error: no matching function for call to" when constructing an unintialized struct
我正在尝试使用此 websocket 服务器的boost::lockfree::spsc_queue
,而不是m_actions
包含此struct
的std::queue
:
enum action_type {
SUBSCRIBE,
UNSUBSCRIBE,
MESSAGE
};
struct action {
action(action_type t, connection_hdl h) : type(t), hdl(h) {}
action(action_type t, server::message_ptr m) : type(t), msg(m) {}
action_type type;
websocketpp::connection_hdl hdl;
server::message_ptr msg;
};
我无法内联初始化此struct
action a = m_actions.front();
因为spsc_queue
没有该功能,而是使用void pop
来设置对象和循环return boolean
。
当我尝试
action a;
while(m_actions.pop(a)){
...
gcc
说:
position_server.cpp:106:11: error: no matching function for call to ‘action::action()’
position_server.cpp:106:11: note: candidates are:
position_server.cpp:39:5: note: action::action(action_type, websocketpp::endpoint<websocketpp::connection<websocketpp::config::asio>, websocketpp::config::asio>::message_ptr)
position_server.cpp:39:5: note: candidate expects 2 arguments, 0 provided
position_server.cpp:38:5: note: action::action(action_type, websocketpp::connection_hdl)
position_server.cpp:38:5: note: candidate expects 2 arguments, 0 provided
position_server.cpp:37:8: note: action::action(const action&)
position_server.cpp:37:8: note: candidate expects 1 argument, 0 provided
如何构建action
然后用spsc_queue.pop()
设置?
这是因为
您的action
类中没有默认构造函数。 它是可以在没有参数的情况下调用的构造函数。
但是当你这样做时:
action a;
您需要此构造函数:
struct action {
action(); // Default constructor
// ...
};
您应该声明并定义它。
当声明没有参数列表的对象值时,将自动调用默认构造函数。(例如 action a;
)。
相关文章:
- "error: no matching function for call to"构造函数错误
- 调用专用模板时出错"no matching function for call to [...]"
- "no matching function for call to 'Vector::Vector'"错误
- 我在 ifstream input_file(文件名)行中收到错误"no matching function to call";
- 为什么当我在 std::string 中打开文件名的 fstream 时出现"no matching function"错误?
- 从 TVector2 类派生复杂类:"No matching function for call to Complex::Complex()"
- 学习 c++,编译错误"no matching function for call"
- C++ "error: no matching function"
- 尝试实例化模板类的对象时出现"No Matching Constructor"错误
- 结构错误:"no matching function for call to "
- 创建函数变体向量时"No matching function for call"错误
- 为什么"std::isdigit"在 Windows 上报告C++"no matching overloaded function"
- 编译时二叉搜索树错误的反向迭代器表示"no matching function call for operator=()"
- 如果子类中没有构造函数方法,则错误"no matching function for call to 'LGame::LGame(String&)'"
- 提升多精度浮点数128:标准::exp错误:'no matching function for call'
- "error: no matching function for call to",我无法更改结构的定义
- 替换派生对象向量中的对象"no matching function to call"
- 我的程序显示许多错误,"error: no matching function for call to 'getPercentScore'"
- 为什么即使我定义了它们"no matching overload found"也会出现错误
- 为什么有一个指向此代码行(第 7 行)的"no matching call for function"错误?