boost::ptr_vector with const members
Hello, I'm trying to use boost::ptr_vector with constant members, like // Excerpt 1 boost::ptr_vector<const int> myVector; myVector.push_back(new int(5)); //This line fails, see comment below myVector[1] = 7; //This should fail, can't assign to const I can do the following with boost::shared_ptr, which is the effect I'm trying to achieve with the above // Except 2 boost::shared_ptr<const int> intPtr(new int(5)); intPtr* = 7; //This won't compile, can't assign to const Returning to excerpt 1, the second line fails, and I don't know why. It causes an error deep within the bowels of the boost. I've tried many permutations placing const in different places, with no luck. Any help or suggestions greatly appreciated! Cheers, Josh Quigley.
Josh Quigley skrev:
Hello,
I’m trying to use boost::ptr_vector with constant members, like
// Excerpt 1
boost::ptr_vector<const int> myVector;
myVector.push_back(new int(5)); //This line fails, see comment below
myVector[1] = 7; //This should fail,
I haven't spent time trying to support ptr_container<const T>, so I don't know if the fix will be easy. I'll put it on my todo list though. Note that void foo( const ptr_vector<int>& vec ) { vec[1] = 7; } fails. I'm not sure I completely understand your analogy though: shared_ptr<T> and a ptr_vector<T> are not similar types; the former is a smart pointer, the latter a container. -Thorsten
Thanks, that is the answer I was after (I now know I wasn't doing anything wrong). As for the analogy, I only wanted to show the behavior of recovering a const pointer. -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Thorsten Ottosen Sent: Friday, 11 May 2007 12:39 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost::ptr_vector with const members Josh Quigley skrev:
Hello,
I'm trying to use boost::ptr_vector with constant members, like
// Excerpt 1
boost::ptr_vector<const int> myVector;
myVector.push_back(new int(5)); //This line fails, see comment below
myVector[1] = 7; //This should fail,
I haven't spent time trying to support ptr_container<const T>, so I don't know if the fix will be easy. I'll put it on my todo list though. Note that void foo( const ptr_vector<int>& vec ) { vec[1] = 7; } fails. I'm not sure I completely understand your analogy though: shared_ptr<T> and a ptr_vector<T> are not similar types; the former is a smart pointer, the latter a container. -Thorsten _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Josh Quigley
-
Thorsten Ottosen