Sign in to follow this  

boost::shared_ptr as member variable

This topic is 4199 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:
//conditioneditor.h
class ConditionEditor : public QWidget
{
	Q_OBJECT
	public:
		ConditionEditor();
		void setText(QString text);
		QString text();
	private:
		QVBoxLayout *layout;
		boost::shared_ptr<int> ptr;
		QString m_text;
		
};

//conditioneditor.cpp
ConditionEditor::ConditionEditor()
	: QWidget(),
	  layout(new QVBoxLayout(this)),
	  ptr(new int(5)),
	  m_text("")
{}
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
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

This topic is 4199 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this