[Moved] [Solved] Crash when taking the address of local variables
-
Edit: moved to the General forum -- peppe
@// foo.h
class foo {
public:
QDataStream m_io;foo();
~foo();bool init(const QString filename);
void check();private:
};
// foo.cpp
foo::foo()
{}
foo::~foo()
{}
bool foo::init(const QString filename)
{
QFile myfile(filename);
if (!myfile.open(QIODevice::ReadWrite))
return false;m_io.setDevice(&myfile); m_io.setByteOrder(QDataStream::BigEndian); return true;
}
void foo::check()
{
qint32 mhead;
m_io >> mhead; // this line causes a segfault :(
}// main.cpp
int main()
{
foo my_foo;my_foo.init("c:\some\file.dat");
my_foo.check(); // crash due to segfaultreturn 0;
}@It's seems to segfault whenever I try and access m_io in any other function than the one it was created in.