How to use a object whose copy constructor and copy assignment is private?

前端 未结 6 575
甜味超标
甜味超标 2021-01-14 07:43

In reading TCPL, I got a problem, as the title refered, and then \'private\' class is:

class Unique_handle {
private:
    Unique_handle& operato         


        
6条回答
  •  醉话见心
    2021-01-14 08:29

    The example you're looking at in Stroustrup's book is demonstrating how the designer of a class can explicitly prevent copying or assignment of objects of that class.

    The class is intentionally making it so your code can't do what you're trying to do (presumably because the class won't function properly or copying otherwise doesn't make sense). If you want to be able to copy objects of that class, you'll need to redesign the class.

    Some other options you might have (which also might not make sense, but that depends on what your really doing) - pass around pointers to references to the object instead of copying.

提交回复
热议问题