title: c++ how to use class initialiser for a non default constructed class
body: <p>I started using SonarLint in VS2019 (c++17)</p>
  <p>I can't figure out how to use a in class initialiser for a non default constructed class</p>
  <pre><code>class Foo
  {
  public:
    Foo(const std::string&amp; str);
  private:
    const std::string m_foostr;
  };
  Foo::Foo(const std::string&amp; str) :
  m_foostr(str)
  {}
  </code></pre>
  <p>Now the sonarlint warning pops up here</p>
  <pre><code>class Bar
  {
  private:
   Foo m_foo;
  };
  
  Bar::Bar() : m_foo(&quot;something) ///&lt; this produces a warning
  {
  }
  </code></pre>
  <p>Sonarlint tells me to use in class initialiser
  <a href="https://rules.sonarsource.com/cpp/RSPEC-3230" rel="nofollow noreferrer">https://rules.sonarsource.com/cpp/RSPEC-3230</a></p>
  <p>How can a achieve this?
  I already tried</p>
  <pre><code>m_foo = Foo(&quot;something&quot;);
  </code></pre>
  <p>and</p>
  <pre><code>m_foo(Foo(&quot;something&quot;));
  </code></pre>
  <p>both result in a compiler error (probably because m_foostr is const).</p>
  <p>Could you help me out here?
  Thx</p>
  <p><strong>Edit</strong>: As requested: The compiler errors are</p>
  <p>the first one results in</p>
  <pre><code>Error C2280: attempting-to-reference-a-deleted-function
  </code></pre>
  <p>the second one results in</p>
  <pre><code>Error 2064 term does not evaluate to a function taking N arguments
  </code></pre>