Skip to main content
gamedev.net
🔒 Locked

boost::shared_ptr as member variable

Started by kiker99 Jun 12, 2006 at 6:57 PM 1 replies 2.3k views
Original Post
kiker99
kiker99
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.
Zahlman
Zahlman
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?
kiker99
kiker99
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.