如果我用-w3编译following code
#include <vector>int main() { std::vector<int> vec; vec.push_back(2); return 0;}
test_w3.cpp(6): remark #383: value copIEd to temporary,reference to
temporary used
vec.push_back(2);
Replacing用一个const变量作为2
#include <vector>int main() { std::vector<int> vec; const int a = 2; vec.push_back(a); return 0;}
没有发出警告.
这个警告意味着什么?可以安全地忽略它(尽管需要无警告代码)吗?
解决方法 英特尔有一个网站正是针对这个问题确切地解决了您的问题 @L_403_2@.它是从2008年开始的,但似乎适用于您的问题.警告存在,因为此编程样式可能会导致隐藏的临时对象,并且在某些情况下可以忽略.他们说明了这个例子:
voID foo(const int &var){}voID foobar(){ std::vector<std::string> numList // 383 remark here: a tempory object with "123" is created numList.push_back("123"); foo(10); // gives 383}
下列:
Resolution:
ProvIDe a proper object for initializing the reference. Can safely ignore this warning for pushback function of vector. The vector copIEs the argument into its own storage; it never stores the original argument. Therefore,using a temporary is perfectly safe.
所以你可能会忽略这个警告,即使这与一般规则相矛盾也绝不会忽视警告.
在我看来,英特尔选择了一种糟糕的方式,因为误诊导致的警告阻碍了发展.
总结以上是内存溢出为你收集整理的c – 警告级别为3的int的std :: vector push_back的编译器警告全部内容,希望文章能够帮你解决c – 警告级别为3的int的std :: vector push_back的编译器警告所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)