"Temporary object" warning - is it me or the compiler?
Posted
by Roddy
on Stack Overflow
See other posts from Stack Overflow
or by Roddy
Published on 2010-05-25T14:05:18Z
Indexed on
2010/05/25
14:11 UTC
Read the original article
Hit count: 281
The following snippet gives the warning:
[C++ Warning] foo.cpp(70): W8030 Temporary used for parameter '_Val' in call to 'std::vector<Base *,std::allocator<Base *> >::push_back(Base * const &)'
.. on the indicated line.
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!
Compiler is Codegear C++Builder 2007.
Oddly, if the constructor for Derived is deleted, the warning goes away... Is it me or the compiler?
© Stack Overflow or respective owner