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

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

Open
hsoriot opened this issue Sep 18, 2024 · 2 comments
Open

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

hsoriot opened this issue Sep 18, 2024 · 2 comments

Comments

@hsoriot
Copy link

hsoriot commented Sep 18, 2024

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

Copy link

Message that will be displayed on users' first issue

@578223592
Copy link
Collaborator

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 我猜测是因为gcc版本的原因,可以尝试升级一下

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