From: Blake D [mailto:BlakeTNC@yahoo.com]
I am a new boost user, and I'm trying to convert a large project to use the smart pointers. I have a use for shared_array buy the memcpy line from the following code snippet(, and all memcpy's) throw an exception with the shared_arrays and I don't know why. Am I doing something obvious wrong?
[snip]
boost::shared_array<uint8> p_data(new uint8[data_length]);
The above declaration of a local variable called p_data is probably not what you intended (you want to initialize the member variable p_data). If you cannot (or won't) perform the initialization in the constructor initializer, you'll need to reset the shared_array like so: p_data.reset(new uint8[data_length]); Or, in the initializer: c_Packet::c_Packet (const c_Packet & r_packet) : p_data(new uint8[r_packed.data_length]) { data_length = r_packet.data_length; ... } ...and then perform the memcpy. By the way, you are actually sharing this data, right? If not, scoped_array would probably be a better choice for managing resource lifetime. Bjorn Karlsson