Why is a public copy constructor required even if it is not invoked?

Viewed 335

Having a public copy constructor will make the little program compile, but not showing the side effect "Copy".

#include <iostream>

class X
{
    public:
    X(int) { std::cout << "Construct" << std::endl; }

    // Having a public copy constructor will make the little program 
    // compile, but not showing the side effect "Copy".

    private:
    X(const X&) { std::cout << "Copy" << std::endl; }

    private:
    X& operator = (const X&);
};

int main() {
    X x = 1;
    return 0;
}
4 Answers
Related