D
dmangal
Hi all...first time poster, long time reader.
I've been experiencing some strange behavior on a Linux development
system (Red Hat 5) compiling a C++ App. I've tried to reduce the
source to something as simple as possible so that I can fit all source
that would still causes my problem. Below are the three simple source
files for class FooClass:
FooClass.hpp:
class FooClass
{
public:
void fooMethod();
private:
typedef struct {
int fooData;
} FooStruct;
};
FooClass.cpp:
#include "FooClass.hpp"
void FooClass::fooMethod()
{
FooStruct* foo;
foo->fooData = 5;
}
main.cpp:
#include "FooClass.hpp"
int main(int argc, char** argv)
{
FooClass* foo = new FooClass();
foo->fooMethod();
delete foo;
return 0;
}
I get no compiler errors but everytime i run this, I get a
segmentation fault. The fault happens at the point when I try to
initialize a member of the data structure, FooStruct ( see line 6 in
FooClass.cpp: foo->fooData = 5; )
Please help as I am stumped.
Oh...and for a side note, this runs with no problem on a different
system running an older version of Linux (Red Hat 4).
Thanks in advance!
dmangal
I've been experiencing some strange behavior on a Linux development
system (Red Hat 5) compiling a C++ App. I've tried to reduce the
source to something as simple as possible so that I can fit all source
that would still causes my problem. Below are the three simple source
files for class FooClass:
FooClass.hpp:
class FooClass
{
public:
void fooMethod();
private:
typedef struct {
int fooData;
} FooStruct;
};
FooClass.cpp:
#include "FooClass.hpp"
void FooClass::fooMethod()
{
FooStruct* foo;
foo->fooData = 5;
}
main.cpp:
#include "FooClass.hpp"
int main(int argc, char** argv)
{
FooClass* foo = new FooClass();
foo->fooMethod();
delete foo;
return 0;
}
I get no compiler errors but everytime i run this, I get a
segmentation fault. The fault happens at the point when I try to
initialize a member of the data structure, FooStruct ( see line 6 in
FooClass.cpp: foo->fooData = 5; )
Please help as I am stumped.
Oh...and for a side note, this runs with no problem on a different
system running an older version of Linux (Red Hat 4).
Thanks in advance!
dmangal