msgpack / msgpack-c

MessagePack implementation for C and C++ / msgpack.org[C/C++]
Other
3.01k stars 877 forks source link

msgpack::v1::adaptor::convert<wchar_t,void>编译错误 #1068

Open cbccy opened 1 year ago

cbccy commented 1 year ago

第一次尝试用msgpack,是否有人遇到过编译测试demo时的头文件重定义错误: msgpack\include\msgpack/v1/adaptor/int.hpp(153): error C2766: 显式专用化;已定义“msgpack::v1::adaptor::convert<wchar_t,void>” msgpack\include\msgpack/v1/adaptor/int.hpp(107): note: 参见“convert<unsigned short,void>”的前一个定义

测试demo如下: `#include

include

include

include

int main() { msgpack::type::tuple<int, bool, std::string> src(1, true, "example");

// serialize the object into the buffer.
// any classes that implements write(const char*,size_t) can be a buffer.
std::stringstream buffer;
msgpack::pack(buffer, src);

// send the buffer ...
buffer.seekg(0);

// deserialize the buffer into msgpack::object instance.
std::string str(buffer.str());

msgpack::object_handle oh =
    msgpack::unpack(str.data(), str.size());

// deserialized object is valid during the msgpack::object_handle instance is alive.
msgpack::object deserialized = oh.get();

// msgpack::object supports ostream.
std::cout << deserialized << std::endl;

// convert msgpack::object instance into the original type.
// if the type is mismatched, it throws msgpack::type_error exception.
msgpack::type::tuple<int, bool, std::string> dst;
deserialized.convert(dst);

// or create the new instance
msgpack::type::tuple<int, bool, std::string> dst2 =
    deserialized.as<msgpack::type::tuple<int, bool, std::string> >();

return 0;

}`

gwankyun commented 1 year ago
#include <msgpack.hpp>

前面加上

#define MSGPACK_USE_CPP03

或者用C++20標準試試。