简体   繁体   中英

Is there any c++ class that can't be used in STL?

Just come up with this question. Any hint?

classes that can't be copied. STL containers require objects to be copyable since the container owns a copy of that object, and needs to be able to move it around.

My favourite thing not to put into a STL container is an std::auto_ptr... very bad things happen. .. mostly unexpected loss of objects I think.

In general anything that is not copyable can't go into a container - you'll get compile errors. Something with abnormal copy semantics (like auto_ptr) should not go in a container (but you probably wont get any compiler errors). As the container is free to create various temporary copies.

I think that without a "sane" default constructor and assignment operator you are also in for some pain.

Depending on the operations you perform, you oftentimes need a default constructor in addition to being copyable for objects stored in containers. For objects passed to algoriths, there are other requirements, like being callable or incrementable. The requirements are well documented.

该类可能不会在析构函数中抛出异常......好吧,任何类都不应该抛出析构函数

Depends on the container, for more information, section 23 of the Standard specifies the requirements for all containers and methods.

To be safe though, you should assume that the following are always required: Default Construction and Copy construction

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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