youngyangyang04 / KVstorageBaseRaft-cpp

【代码随想录知识星球】项目分享-基于Raft的k-v存储数据库🔥
533 stars 106 forks source link

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

Open hsoriot opened 19 hours ago

hsoriot commented 19 hours ago

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" 这个编译错误是我的环境引起的吗?

github-actions[bot] commented 19 hours ago

Message that will be displayed on users' first issue