How to assign ifstream& return from method to variable?
<p>I have a method name <code>open_file</code> declare as below.</p>

<pre><code>ifstream&amp; open_file(ifstream &amp;in, const string &amp;filename)
{
    in.close();
    in.clear();

    in.open(filename.c_str());

    return in;
}
</code></pre>

<p>I want to assign its return value to variable in main() method:</p>

<pre><code>int main()
{
    ifstream val1;
    ifstream val2 = open_file(val1, "test.cpp");

    return 0;
}
</code></pre>

<p>I can't compile the code. My questions are:</p>

<ol>
<li>Can I assign return value from open_file method to variable in main(), and if so how to do that?</li>
<li>If I can't assign return value from open_file method to variable, what's the difference if I change its return type to void?</li>
</ol>
