Weird segmentation fault when calling virtual method, HELP
<p>Here is my code, I casted the buffer to different type of objects, is this what causes the failure? I really want to know why the <strong>FromBase::find2(int key) works, but not FromBase::find(int key)?</strong></p>

<pre><code>class Base
{
 public:
        virtual int find(int key)=0;

        int keys[4];
};

class FromBase:public Base
{
 public:
       FromBase();
       int find(int key);
       int find2(int key);
};
FromBase::FromBase()
{
       for(int i=0;i&lt;4;i++)
              keys[i]=-1;
}
int FromBase::find(int key)
{
       for(int i=0;i&lt;4;i++){
              if(keys[i]==key)
                    return i;
       }
       return i;
};
int FromBase::find2(int key)
{
       for(int i=0;i&lt;4;i++){
              if(keys[i]==key)
                    return i;
       }
       return i;
};

int main()
{
       FromBase frombase;
       FILE* fptr=fopen("object.dat","w");
       fwrite((void*)&amp;frombase,48,1,fptr);
       fclose(fptr);

       char object[48];
       fptr=fopen("object.dat","r");
       fread((void*)object,48,1,fptr);

       // looks like this works
       (FromBase*)object-&gt;find2(7);

       //These two do not work, I got segmentation fault!
       (FromBase*)object-&gt;find(7); 
       (Base*)object-&gt;find(7);     
}
</code></pre>

<p>The reason I want to do this is because I need to read the object from a file, thus I need to cast the buffer to an particular type then I can call the mothod.</p>
