Msgstr "error: there is no corresponding function to call" when building an unintelliged structure

I am trying to use boost::lockfree::spsc_queue with this websocket server instead of std::queue for m_actions to contain this struct :

 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; }; 

I cannot initialize this struct inline with

 action a = m_actions.front(); 

because spsc_queue does not have this function, but uses void pop to set the object and return boolean for the loop.

When i try

 action a; while(m_actions.pop(a)){ ... 

gcc says:

 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 

How can I build an action and then set using spsc_queue.pop() ?

+4
source share
1 answer

This is because you do not have a default constructor in your action class. This is a constructor that can be called without an argument .

But when you do:

 action a; 

You need this constructor:

 struct action { action(); // Default constructor // ... }; 

You must declare and define it.

The default constructors are automatically called when an object value is declared without a list of arguments. (e.g. action a; ).

+3
source

Source: https://habr.com/ru/post/1502127/


All Articles