Jump to content
  • Advertisement
Sign in to follow this  

boost::shared_ptr as member variable

This topic is 4481 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

Hey guys, i'm working with g++, boost and Linux and am trying to get this running:
class ConditionEditor : public QWidget
		void setText(QString text);
		QString text();
		QVBoxLayout *layout;
		boost::shared_ptr<int> ptr;
		QString m_text;

	: QWidget(),
	  layout(new QVBoxLayout(this)),
	  ptr(new int(5)),
Forget about the Qt Stuff. Also the pointer type int is just an example here to make things easier. I get a segfault when executing this code. I get a segfault as long as i'm using a smart pointer as a member variable. It doesn't matter if it isn't initialized, or if it's initialized via MIL (as above) or via assignment. I don't get why I can't use the smart pointer as a member. If I put it into the constructor (which doesn't make sense for what I want), the code compiles and executes. Any ideas? EDIT: uhm, I still forgot another thing I tried. I made the smart pointer static. Then the program didn't crash anymore. Why that? The problem is that I don't want the variable to be static.

Share this post

Link to post
Share on other sites
How are you using the object?

Did you try it with just the smart pointer as a member, to be sure the problem is there?

How, if at all, have you attempted to debug this so far?

Share this post

Link to post
Share on other sites
thx, Zahlman, for your reply.

This is very odd. Today everything just works as expected. I will check my RAM tonight, there seems something to be broken at hardware level. My Computer also crashed today one time, what i am not used to.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!