zeromq / cppzmq

Header-only C++ binding for libzmq
http://www.zeromq.org
MIT License
1.93k stars 757 forks source link

Call to constructor of 'zmq::message_t' is ambiguous #585

Closed L-Super closed 1 year ago

L-Super commented 1 year ago

When I use the following code, I encounter an error

const char* str{"hello"};
zmq::message_t m{str};
Call to constructor of 'zmq::message_t' is ambiguous

image

It seems that const string& and string_view are in conflict.

sigiesec commented 1 year ago

You need to explicitly cast to std::string_view in the call to the constructor. Or you could just use std::string_view instead of const char* in the first place.

L-Super commented 1 year ago

I want to use it as a template function. How can I improve it?

template <typename String>
std::string send(String str)
{
//....
zmq::message_t m{str};
socket.send(m, zmq::send_flags::none);
//....
}

int main()
{
//...
send("hello");
}
gummif commented 1 year ago

Maybe just

std::string send(std::string_view str)
{
...
}