boost::shared_ptr<const T>
Is it legal to construct a boost::shared_ptr<const T> from a raw T*? On MSVC6, it produces errors when class T has an implicit destructor, but compiles without error otherwise. ----------------------------------------------------------------------- Andrew R. Thomas-Cramer Work: artc@prism-cs.com http://www.prism-cs.com/ Home: artc@execpc.com http://www.execpc.com/~artc/ ----------------------------------------------------------------------- [Non-text portions of this message have been removed]
From: "Andrew R. Thomas-Cramer" <artc@prism-cs.com>
Is it legal to construct a boost::shared_ptr<const T> from a raw T*?
Yes, it's legal.
On MSVC6, it produces errors when class T has an implicit destructor, but compiles without error otherwise.
Seems to work for me; coud you post an example?
----- Original Message ----- From: "Peter Dimov" <pdimov@mmltd.net> To: <Boost-Users@yahoogroups.com> Sent: Monday, May 13, 2002 1:41 PM Subject: Re: [Boost-Users] boost::shared_ptr<const T>
From: "Andrew R. Thomas-Cramer" <artc@prism-cs.com>
Is it legal to construct a boost::shared_ptr<const T> from a raw T*?
Yes, it's legal.
Neat!
On MSVC6, it produces errors when class T has an implicit destructor, but compiles without error otherwise.
Seems to work for me; coud you post an example?
I'm using boost 1.27 and MSVC6.0. Here's example code, followed by the compiler error: #include <boost/shared_ptr.hpp> class With { public: With() { } ~With() { } }; class Without { public: Without() { } }; int main() { boost::shared_ptr<const With> pWith( new With() ); boost::shared_ptr<const Without> pWithout( new Without() ); return 0; } Compiling... main.cpp d:\projects\lib\boost\boost_1_27_0\boost\checked_delete.hpp(27) : error C2665: 'delete' : none of the 2 overloads can convert parameter 1 from type 'const class Without *' d:\projects\lib\boost\boost_1_27_0\boost\checked_delete.hpp(43) : see reference to function template instantiation 'void __cdecl boost::checked_delete(const class Without *)' being compiled Error executing cl.exe.
From: "Andrew R. Thomas-Cramer" <artc@prism-cs.com>
On MSVC6, it produces errors when class T has an implicit destructor,
but
compiles without error otherwise.
Seems to work for me; coud you post an example?
I'm using boost 1.27 and MSVC6.0. Here's example code, followed by the compiler error:
[...] This is a compiler-specific error, I believe; MSVC 6 doesn't like deleting const pointers. You can use shared_ptr<T const> p = shared_ptr<T>(new T); The new release has a templated constructor so shared_ptr<T const> p(new T); works as-is.
participants (2)
-
Andrew R. Thomas-Cramer
-
Peter Dimov