Is it possible to disallow taking a reference to an object

后端 未结 2 1973
星月不相逢
星月不相逢 2020-12-18 20:21

I want to do the opposite of making instances of a class noncopyable, that is, make sure that instances of a particular class can be passed only as a c

2条回答
  •  無奈伤痛
    2020-12-18 20:45

    That's impossible. Any named variable can bind to a reference variable of the appropriate type. That's just how the language works.

    In particular, you could never have a copy constructor with your restriction, so you couldn't actually pass the object by value!

提交回复
热议问题