May 28, 2013 at 9:46am UTC
you are trying to push variable to vector containing pointers to said variable.
Maybe you want to push its address ?
a.push_back(& abb);
May 28, 2013 at 9:49am UTC
It's not safe to add "abb " to "abbonato::a " since the referent of "abb " may be a temporary object.
Wazzak
Last edited on May 28, 2013 at 9:49am UTC
May 28, 2013 at 9:52am UTC
abb should be a pointer to type abbonato.
May 28, 2013 at 9:53am UTC
MiiNiPaa, thank you for the reply, but I want to save the value located in the abb's address
May 28, 2013 at 9:53am UTC
abb
is const
. You cannot push_back()
it as a non const pointer. Try this:
a.push_back(new abbonato(abb));
May 28, 2013 at 10:02am UTC
Thank you coder777, and for example, if abbonato is an abstract class, from which I derive some subclasses and a is a vector of polymorphic pointers? I cannot allocate an object of abstract type.
May 28, 2013 at 10:04am UTC
Make abb non-const and pass address to push_back()
May 28, 2013 at 10:07am UTC
But so I save the address, not the value, or not?!