Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > boost::shared_p...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 9347 of 10096
Post > Topic >>

boost::shared_ptr used in covariant return type

by zade <zhaohongchao@[EMAIL PROTECTED] > Mar 5, 2008 at 10:41 AM

boost::shared_ptr is good for return type when you create a new type
using pimpl idiom, but in practice, it gives me some trouble when used
for covariant return type. code like below:
	struct Object
	{
	public:
		virtual ~Object()
		{}
	};
	typedef boost::shared_ptr<Object> ObjectPtr;

	struct Cloneable: public Object
	{
	public:
		virtual ~Cloneable()
		{}
		//virtual Object* Clone() const = 0;//	it is ok in this form
		virtual ObjectPtr Clone() const = 0;// it is wrong in this form, see
Foo below
	};
	struct Foo;
	typedef boost::shared_ptr<Foo> FooPtr;
	struct Foo : public Cloneable
	{
		//virtual Foo* Clone() const // it is ok in this form
		//{
		//	return new Foo();
		//}
		virtual FooPtr Clone() const// it is wrong in this form
		{
			return  boost::shared_ptr<Foo>(new Foo());
		}
	};
so, any advice?
thanks!

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 3 Posts in Topic:
boost::shared_ptr used in covariant return type
zade <zhaohongchao@[EM  2008-03-05 10:41:58 
Re: boost::shared_ptr used in covariant return type
Ulrich Eckhardt <dooms  2008-03-05 16:31:18 
Re: boost::shared_ptr used in covariant return type
Nicola Musatti <nicola  2008-03-06 10:38:54 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 8:34:10 CDT 2008.