KVstorageBaseRaft-cpp icon indicating copy to clipboard operation
KVstorageBaseRaft-cpp copied to clipboard

util.h编译报错,snprintf不接受非平凡类型

Open hsoriot opened this issue 5 months ago • 2 comments

error: cannot pass object of non-trivial type 'std::basic_string' through variadic function; call will abort at runtime [-Wnon-pod-varargs] int size_s = std::snprintf(nullptr, 0, format_str, args...) + 1; // "\0"

我在make时候遇到了这个错误,gpt解释是snprinf不能接受非平凡类型,args无法提供保证。提供给我的解决方案是把args先转成string再转成const char*。修改后完成了编译 std::ostringstream oss; (oss << ... << args); int size_s = std::snprintf(nullptr, 0, format_str, oss.str().c_str()) + 1; // "\0" 这个编译错误是我的环境引起的吗?

hsoriot avatar Sep 18 '24 18:09 hsoriot