Implementing a non-copyable C++ class : <p>In Visual Studio 2019, I am trying, without success, to implement the technique for making a class non-copyable shown for C++11, and later, at the accepted answer at <a href="https://stackoverflow.com/questions/2173746/how-do-i-make-this-c-object-non-copyable"><em>How do I make this C++ object non-copyable?</em></a>.</p>

<p>My class is,</p>

<pre><code>class Foo {

public:
    Foo();
    Foo(std::string name);
    ~Foo();

    std::string m_name;

    static std::int32_t s_counter;

public:
    Foo(const Foo&amp; inFoo) = delete;
    Foo&amp; operator=(const Foo&amp; inFoo) = delete;
};
</code></pre>

<p>The definition code is,</p>

<pre><code>std::int32_t Foo::s_counter = 0;

Foo::Foo(void)
{
    Foo::s_counter++;
    std::cout &lt;&lt; "Foo constructor.  Count = " &lt;&lt; Foo::s_counter &lt;&lt; std::endl;
}

Foo::Foo(std::string name)
{
    Foo::s_counter++;
    m_name = name;
    std::cout &lt;&lt; "Foo " &lt;&lt; m_name &lt;&lt; " constructor.  Count = " &lt;&lt; Foo::s_counter &lt;&lt; std::endl;
}

Foo::~Foo()
{
    Foo::s_counter--;
    std::cout &lt;&lt; "Foo destructor.  Count = " &lt;&lt; Foo::s_counter &lt;&lt; std::endl;
}

</code></pre>

<p>It is used in,</p>

<pre><code>int main(int argc, char** argv) {

    std::vector&lt;Foo&gt; fooVector;

    {
        Foo myFoo1{ Foo() };
        fooVector.push_back(std::move(myFoo1));

        Foo myFoo2{ Foo("myFoo2") };
        fooVector.push_back(std::move(myFoo2));
    }

    if (Foo::s_counter &lt; 0) {

        std::cout &lt;&lt; "Foo object count = " &lt;&lt; Foo::s_counter &lt;&lt; std::endl;
    }

    std::cin.get();
}
</code></pre>

<p>in which I have intentionally scoped the definition of <code>myFoo1</code> and <code>myFoo2</code> so as to get object count feedback.</p>

<p>When the copy constructor and assignment constructor are made <code>public</code>, as shown, the compile error is "C2280   'Foo::Foo(const Foo &amp;)': attempting to reference a deleted function". When they are made private, the compile error is "C2248   'Foo::Foo': cannot access private member declared in class 'Foo'".</p>

<p>I believe I am misinterpreting something in the original SO answer, but I cannot see what it is.</p>
