What's the most reliable way to prohibit a copy constructor in C++?

前端 未结 6 2062
情话喂你
情话喂你 2020-11-28 10:43

Sometimes it\'s necessary to prohibit a copy constructor in a C++ class so that class becomes \"non-copyable\". Of course, operator= should be prohibited at the

6条回答
  •  Happy的楠姐
    2020-11-28 11:26

    The first one is better

    Even better is C++0x 'delete' keyword:

    class Class {
    // useful stuff, then
    public:
        Class(const Class&) = delete;
        void operator=(const Class&) = delete;
    };
    

提交回复
热议问题