mercredi 29 mars 2017

How to make_shared count times, with different areas allocated without recur to a loop?

How to make_shared count times, with different areas allocated without recur to a loop?

I have the following code:

for( unsigned int count = 0; count < demandedSize; ++count  )
{   
   m_connectionList.push_back( std::make_shared< Foo >( m_ip, m_port )); 
}

How to shorten this without a loop?

I know std::vector receaves a second argument as const T&, but in that case all shared_ptrs points to the same address (value is copied).

std::vector< std::shared_ptr<Foo> > vet( demandedSize, std::make_shared<Foo>( m_ip, m_port ) );

How to execute make_shared count times, with different areas allocated as result without recur to a loop

Aucun commentaire:

Enregistrer un commentaire