非POD对象错误 [英] Non-POD object error

查看:245
本文介绍了非POD对象错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我已经阅读了很多在线的这个错误,但由于某种原因,我仍然得到它,即使我已经尝试建议的事情后。如果任何人可以帮助我理解这一点,指出出了什么问题,那将是真棒。

So, I've read a lot online for this error, but for some reason, I'm still getting it even after I have tried the suggested things. If anyone could help me understand this and point out what's wrong, that would be awesome.

char * s = strtok(text, ",");
string name = s;
printf("%s", name);


推荐答案

像您不能将非POD对象传递到省略号。这是因为您试图将非POD类型传递给一个可变参数的变量函数。在这种情况下,调用 printf ,其声明如下所示

Given your example code the error you get is saying something like you cannot pass a non-POD object to an ellipses. This is because you are trying to pass a non-POD type to a variadic function, one that takes a variable number of arguments. In this case by calling printf which is declared something like the below

int printf ( const char * format, ... );

作为最后一个参数的省略号允许你传递0个或多个额外的参数给你的函数正在做你的代码。 C ++标准确实允许您传递非POD类型,但编译器不是必需支持它。

The ellipsis used as the last parameter allows you to pass 0 or more additional arguments to the function as you are doing in your code. The C++ standard does allow you to pass a non-POD type but compilers are not required to support it. This is covered in part by 5.2.2/7 of the standard.


传递一个潜在评估的类类型的参数,非实值复制构造函数,非平凡移动构造函数或非平凡析构函数,没有相应的参数,由实现定义的语义有条件支持。

Passing a potentially-evaluated argument of class type having a non-trivial copy constructor, a non-trivial move contructor, or a non-trivial destructor, with no corresponding parameter, is conditionally-supported with implementation-defined semantics.

这意味着由每个编译器制造者决定是否他们希望支持它的行为。显然,你的编译器不支持这个,即使它是我不会推荐使用它。

This means it is up to each compiler maker to decide if they want to support it and how it will behave. Apparently your compiler does not support this and even if it did I wouldn't recommend using it.

这篇关于非POD对象错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆