下面的代码片段给出了警告:“临时对象”警告 - 是我还是编译器?
[C++ Warning] foo.cpp(70): W8030 Temporary used for parameter '_Val' in call to 'std::vector<Base *,std::allocator<Base *> >::push_back(Base * const &)'
..在指定的行。
class Base
{
};
class Derived: public Base
{
public:
Derived() // << warning disappears if constructor is removed!
{
};
};
std::vector<Base*> list1;
list1.push_back(new Base);
list1.push_back(new Derived); // << Warning on this line!
编译器是CodeGear的C++ Builder的2007年
奇怪的是,如果Derived被删除的构造,警告消失...... 是我还是编译器?
编辑:我发现删除警告的唯一方法就是类似于这样:
Derived * d;
list1.push_back(d = new Derived); // << No warning now...
此代码没有警告与gcc。 – kriss 2010-05-25 14:20:15
这可能不是所有代码。 Base和Derived是否有构造函数(非编译器生成的)? – 2010-05-25 14:22:37
@MadKeithV - 给予或采取#include,这是所有的代码。我从一个更复杂的案例开始,将其切割成显示上述问题的裸露骨骼。 –
Roddy
2010-05-25 14:31:10