This is a follow up of C++ : Coverity reports leaks for peculiar use of references and containers
Question: *b
is allocated on the heap ( new B()
) but where are a_vector
and its elements stored? What happens when new elements are pushed into a_vector
?
int main()
{
...
B* b = new B();
A a;
b->add_a_to_b( a );
...
delete (b);
}
class B {
public:
std::vector<A> a_vector;
void add_a_to_b( const A& a )
{
a_vector.push_back( a );
}