Compiler warning when using vector of pointers

From: Adrian (nntp_at_bluedreamer.com)
Date: 10/31/04


Date: Sun, 31 Oct 2004 17:03:04 +0000 (UTC)

Hi all,

I am getting a warning compiling the following code using Borland C++
Builder 6, but I dont think I am doing anything wrong. When using g++ I
get no warnings at all with a g++ -Wall -ansi -pedantic.

Now I usually assume the compiler is correct but in this case I am not sure.

push 1 gives the warning the other 2 go through fine.

The warning text is:-
"C:\temp>bcc32 a.cpp
Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland a.cpp:
Warning W8030 a.cpp 24: Temporary used for parameter '__x' in call to
'_STL::vector<A *,_STL::allocator<A *> >::push_back(A * const &)' in
function main()
Turbo Incremental Link 5.66 Copyright (c) 1997-2002 Borland"

I cant see why a temporary is being created, what am I missing

TIA

--------------

#include <vector>

class A
{
   public:
     virtual ~A()=0;
   private:
};

A::~A()
{
}

class BA : public A
{
   public:
   private:
};

int main()
{
   std::vector<A *> fred;

   fred.push_back(new BA()); // push 1 Gives warning

   A *ptr=new BA();
   fred.push_back(ptr); // push 2
   fred.push_back(ptr=new BA()); // push 3

   return 0;
}



Relevant Pages

  • Input Iterator needed for a for_each.
    ... I have a project that use to be developped on WIndows NT 4.0 sp6a and ... Borland c++ builder 5.0. ... I have a warning on each std::for_each use. ... iterator: input iterator required" ...
    (comp.lang.cpp)
  • Re: Delphi 2005 & BDE
    ... will keep BDE + ODBC. ... > Rick Carter wrote: ... >> Borland has been warning for years that it is only safe to use ...
    (borland.public.delphi.non-technical)
  • Re: [C] assignment warnings
    ... >bcc32 (with/without parentheses around assignment) ... >warning: Possibly incorrect assignment ... situation where I really _have_ written an "incorrect assignment" ... You gotta love the Borland compiler...in testing this, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: malloc? I am lost again
    ... > If I ignore the warning, ... This is due to an combined assignment and test. ... Borland seems to be very picky. ...
    (comp.lang.c)
  • Re: Borland kills another developer tool
    ... > This was an announcement that came out of the blue with no warning. ... Borland is doing the right thing in folding Codewright technology into its ... major IDEs, and the idea that Borland would consolidate its IDE code was ... mentioned in this forum almost a year ago (May 7, 2003 to be exact, thread ...
    (borland.public.delphi.non-technical)