How do I make this C++ object non-copyable?

前端 未结 10 976
太阳男子
太阳男子 2020-11-28 04:36

See title.

I have:

class Foo {
   private:
     Foo();
   public:
     static Foo* create();
}

What need I do from here to make Fo

10条回答
  •  无人及你
    2020-11-28 05:10

    The typical way to make a C++ object non-copyable is to explicitly declare a copy constructor and copy-assignment operator but not implement them. This will prevent the compiler from generating its own. (Typically this is done in conjunction with declaring them private so that it generates a compilation error instead of a linker error.)

    There also is the boost::noncopyable class that you can inherit from, which does what I described above.

提交回复
热议问题