title: Selection of istream from cin or file with ternary operator
body: <p>I would like to have a member variable of a class which stores the input stream depending on a string entered by the user. eg.</p>
  <pre><code>#include &lt;string.h&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  class myInput {
  public:
      myInput(std::string file_name);
      myInput() = delete;
  
  protected:
      std::istream&amp; in_data;
  };
   
  myInput::myInput(std::string file_name)
      : in_data((file_name == &quot;-&quot;) ? std::cin : std::ifstream(file_name)){}
  
  void main() {
      myInput(&quot;file.txt&quot;);
  }
  </code></pre>
  <p>However I am receiving the following errors</p>
  <pre><code>error: use of deleted function ‘std::basic_istream&lt;_CharT, _Traits&gt;::basic_istream(const std::basic_istream&lt;_CharT, _Traits&gt;&amp;) [with _CharT = char; _Traits = std::char_traits]’
  error: ‘std::basic_istream&lt;_CharT, _Traits&gt;::basic_istream(const std::basic_istream&lt;_CharT, _Traits&gt;&amp;) [with _CharT = char; _Traits = std::char_traits]’ is protected within this context
  </code></pre>
  <p>I have also tried creating the <code>ifstream</code> object separately and assigning that to <code>in_data</code>, but encounter similar problems. Why is this?</p>