Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error when using lambda to subscribe to a signal in sigslot #48

Open
2stLv opened this issue Oct 10, 2024 · 2 comments
Open

Comments

@2stLv
Copy link

2stLv commented Oct 10, 2024

I want to replace boost signals2 with sigslot. But code that does not report an error using boost signals2 will report an error using sigslot.
`enum class EventType : uint32_t
{
_1,
};

class CBaseData
{
public:
CBaseData()
{
}
virtual ~CBaseData()
{
}

public:
private:
};

using tPublisherSignal = sigslot::signal< void( EventType ,const CBaseData &)>;
using tPublisherConnect = sigslot::connection;

tPublisherSignal mSig;

tPublisherConnect subscribeEvent(const std::function<void(EventType, const CBaseData &)> &subscriber) {
return mSig.connect(subscriber);
}

int main() {
subscribeEvent([](EventType, const CBaseData &) {
//std::cout << typeid(CBaseData).name() << std::endl;
});
}`
image

BUILD info:
/Users/wanglei/Code/Git/sigslot/example/basic.cpp:97:17: error: no matching member function for call to 'connect' 97 | return mSig.connect(subscriber); | ~~~~~^~~~~~~ /Users/wanglei/Code/Git/sigslot/include/sigslot/signal.hpp:1244:5: note: candidate template ignored: requirement 'trait::is_callable_v<sigslot::trait::typelist<void (EventType, const CBaseData &)>, const std::function<void (EventType, const CBaseData &)> &>' was not satisfied [with Callable = const std::function<void (EventType, const CBaseData &)> &] 1244 | connect(Callable && c, group_id gid = 0) { | ^ /Users/wanglei/Code/Git/sigslot/include/sigslot/signal.hpp:1285:5: note: candidate function template not viable: requires at least 2 arguments, but 1 was provided 1285 | connect(Pmf && pmf, Ptr && ptr, group_id gid = 0) { | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/wanglei/Code/Git/sigslot/include/sigslot/signal.hpp:1306:5: note: candidate function template not viable: requires at least 2 arguments, but 1 was provided 1306 | connect(Pmf && pmf, Ptr && ptr, group_id gid = 0) { | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/wanglei/Code/Git/sigslot/include/sigslot/signal.hpp:1354:5: note: candidate function template not viable: requires at least 2 arguments, but 1 was provided 1354 | connect(Pmf && pmf, Ptr && ptr, group_id gid = 0) { | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/wanglei/Code/Git/sigslot/include/sigslot/signal.hpp:1384:5: note: candidate function template not viable: requires at least 2 arguments, but 1 was provided 1384 | connect(Callable && c, Trackable && ptr, group_id gid = 0) { | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. ninja: build stopped: subcommand failed.

@palacaze
Copy link
Owner

Can you try changing subscribeEvent(const std::function<> &) to subscribeEvent(std::function<>)?

@2stLv
Copy link
Author

2stLv commented Oct 11, 2024

Can you try changing subscribeEvent(const std::function<> &) to subscribeEvent(std::function<>)?

don`t work ,same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants