简体   繁体   English

以下代码段是什么意思

[英]what does the following code snippet mean

I have a class named BridgeChannel. 我有一个名为BridgeChannel的类。 It has some things under the private sections. 它在私有部分下有一些内容。 I don't know what they do. 我不知道他们在做什么。

private:

  BridgeChannel (const BridgeChannel &);
  BridgeChannel &operator = (const BridgeChannel &);

Your ideas and knowledge is greatly apprecitated. 您的想法和知识非常感激。

It means that the copy constructor and copy assignment operator are private . 这意味着复制构造函数和复制赋值运算符是private This way objects of type BridgeChannel cannot be copied or assigned outside of BridgeChannel . 这样,无法在BridgeChannel外部复制或分配类型为BridgeChannel对象。

This is useful if your class contains some resource which is impossible, too costly, or nonsensical to copy. 如果您的班级包含一些不可能,太昂贵或无法复制的资源,这将很有用。

In C++11 this idiom has been replaced by marking those functions as = delete , which serves the same purpose but provides clearer error messages. 在C ++ 11中,此惯用语已被标记为= delete那些功能所代替,该功能具有相同目的,但提供了更清晰的错误消息。

An old helper to simplify this idiom is to inherit from boost::noncopyable . 简化此习语的老帮手是继承boost::noncopyable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM