Segfault when accessing private variable in header file?

Hey all this is my first post! Recently just finished a program but I am getting a segmentation fault when I try to call a switch statement with a private variable from the header file as the switch.

Here is the function with the switch statement in *.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
int inode::get_type(){
  int type_int = 2;
  switch(type){  //gdb backtraced to here
    case DIR_INODE:
      type_int = 0;
      break;
    case FILE_INODE:
      type_int = 1;
      break;
  }
  return type_int;
}


and here is where the variable "type" is located:
1
2
3
4
5
6
7
8
9
10
11
12
class inode {
   private:
      int inode_nr;
      inode_t type; 
      union {
         directory *dirents;
         wordvec *data;
      } contents;
      static int next_inode_nr;
   public:
      //more prototypes
}


Any help is greatly appreciated! also, if it matters, main is in a completely diff *.cpp file.
Last edited on
Perhaps type is not initialized? It's hard to tell without your constructor being shown.
Perhaps the "this" pointer is invalid? This could be caused by "dereferencing" functions of object pointers that are invalid.
Where is the type define for "inode_t"?

To set a break point before the "switch", and then print "type" before switch to see what's value of it.



b2ee
Topic archived. No new replies allowed.