[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppScopedArray

(C++) boost::scoped_array

a smart pointer available in the Boost C++ Library. It enables you to dynamically create an array that goes out of scope automatically.

//Standard way
{
  const int size = rand()%69;
  int * myPlainArray = new int[size];
  //Code
  delete[] myPlainArray;
}
//Using the boost::scoped_array
{
  boost::scoped_array<int> myArray(rand()%69);
  //Code
  //Nothing! myArray deletes[] itself when going out of scope!
}


Why is the boost::scoped_array not in the STL, where std::auto_ptr is ?

On the website of Bjarne Stroustrup he stated that the boost::scoped_array was not necessary. I guess, this is because a std::vector can be used instead, which has similar behaviour.

Link

  • http://www.boost.org/


last edited (November 16, 2006) by bilderbikkel, Number of views: 2934, Current Rev: 7 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.