Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


'boost::weak_ptr<T>' does not have an overloaded member 'operator ->'

This topic is 5910 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Really? Doesn''t that make it less useful, at least from a code readability POV? Maybe I''m not using this right:

	boost::shared_ptr<CCommand> m_DataSource;


inline boost::weak_ptr<CCommand> CVisualComponent::GetDataSource(void) const
	return boost::weak_ptr<CCommand>(m_DataSource);
later in a derived class: GetDataSource().get()->Execute(m_Text); Am I using it correctly? I would have hoped for smart pointer to be less intrusive an in all instances just pretend to be the pointer they manage. I looked over the Doco, they don''t mention anything about and -> evilness so I''m left wondering if this is how I''m meant to use it... Many thanks, Chris Brodie http:\\fourth.flipcode.com

Share this post

Link to post
Share on other sites
weak_ptr is a non-owning smart pointer. It sounds like you want an owning smart pointer, which would be shared_ptr.

Share this post

Link to post
Share on other sites
Original post by gimp
Whats a weak pointer used for then may I ask? I just don't get it yet...

It allows you to get a handle to a pointer that is managed elsewhere, and to track the validity of that pointer. A weak_ptr will generally be constructed from an owning smart pointer, and will retain a connection with that smart pointer so that it knows when the pointed to object is no longer valid. Say you want a class to retain a pointer to an object, but you do not want that class to affect the lifetime of the object, you would use a weak_ptr, and transform that into either a shared_ptr or a "dumb pointer" (via get) whenever you want to access the object - first ensuring that the object is still alive.

[edited by - SabreMan on August 13, 2002 7:33:18 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!