Segmentation fault (core dumped) in c++ Can't find error
<p>I dont seem to be able to find the source of the error. The code defines a struct called boolfunc. I define a function to add two boolfunc(s). I get the error: segmentation fault (core dumped). I know what it means but where is the source of the error.</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;vector&gt;
using namespace std;

class boolfunc {
public:
  int num_var;
  int num_terms;
  vector&lt;vector&lt;int&gt; &gt; func;
  boolfunc addfunc(boolfunc f1, boolfunc f2);
};

boolfunc addfunc(boolfunc f1, boolfunc f2)
  {
    boolfunc f3;
    f3.func.resize(0);
    f3.num_terms = f1.num_terms + f2.num_terms;
    int var_dif = f1.num_var - f2.num_var;
    if(var_dif &gt;= 0)
        {
        f3.num_var=f1.num_var;
        f3.func.resize(f1.num_var);
        f2.num_var=f1.num_var;
            f2.func.resize(f1.num_var);
        for(int i=0; i&lt;f2.num_terms; ++i)
            {
            for(int j=0; j&lt;var_dif; ++j)
                {
                f2.func[i].push_back(-1);
                }
            }
        }
    else
        {
        f3.num_var=f2.num_var;
        f3.func.resize(f2.num_var);
        f1.num_var=f2.num_var;
        f1.func.resize(f2.num_var);
        for(int i=0; i&lt;f1.num_terms; ++i)
            {
            for(int j=0; j&lt;(-1)*(var_dif); ++j)
                {
                f1.func[i].push_back(-1);
                }
            }
        }
    for(int i=0; i&lt;f1.num_terms; ++i)
        {
        f3.func[i]=f1.func[i];
        }   
    for(int j=0; j&lt;f2.num_terms;++j)
        {
        f3.func[j+f1.num_terms]=f2.func[j];
        }
    return f3;
    }

int main()
{
boolfunc ef1, ef2, ef3;
ef1.func.resize(0);
ef2.func.resize(0);
ef3.func.resize(0);
cout&lt;&lt; "Input the number of variables of function 1" &lt;&lt;endl;
cin&gt;&gt; ef1.num_var;
cout&lt;&lt; "Input the number of variables of function 2" &lt;&lt;endl;
cin&gt;&gt; ef2.num_var;
cout&lt;&lt; "Input the number of terms of function 1" &lt;&lt;endl;
cin&gt;&gt; ef1.num_terms;
cout&lt;&lt; "Input the number of terms of function 2" &lt;&lt;endl;
cin&gt;&gt; ef2.num_terms;
ef1.func.resize(ef1.num_terms);
  for(int i=0; i&lt;ef1.num_terms; ++i)
    {
    ef1.func[i].resize(ef1.num_var);
    for(int j=0; j&lt;ef1.num_var; ++j)
        {
    cout&lt;&lt;"For function 1, Input the term "&lt;&lt;i+1&lt;&lt;"'s variable "&lt;&lt;j+1&lt;&lt;"'s     value:";
        cin&gt;&gt;ef1.func[i][j];
        }
    }
ef2.func.resize(ef2.num_terms);
  for(int i=0; i&lt;ef2.num_terms; ++i)
    {
    ef2.func[i].resize(ef2.num_var);
    for(int j=0; j&lt;ef2.num_var; ++j)
        {
    cout&lt;&lt;"For function 2, Input the term "&lt;&lt;i+1&lt;&lt;"'s variable "&lt;&lt;j+1&lt;&lt;"'s     value:";
        cin&gt;&gt;ef2.func[i][j];
        }
    }
ef3 = addfunc(ef1, ef2);
for(int i=0; i&lt;ef3.num_terms; ++i)
    {
    for(int j=0; j&lt;ef3.num_var; ++j)
        {
        cout&lt;&lt;ef3.func[i][j]&lt;&lt;' ';
        if(j==ef3.num_var -1) cout&lt;&lt;endl;
        }
    }
return 0;
}
</code></pre>
