c++ - would deleting copy constructor/assignment break standard library operations -


i have few classes requirements instances must not have similar copies @ runtime. let's 1 of class looks -

class a{     int id;     int printernum;      bool failstate = true;     //....  public:     //....  }; 

now id , printernum must unique each instance since no 2 instance can control same printer @ time. id generated @ construction of object printernum can change. these 2 requirements, provide checks @ constructor , failstate variable never initializes object , sets failstate true if bad occurs.

also thinking of deleting copy constructor , assignment operator make sure user never creates copy , can initialize constructor id , printernum remain unique.

but before making change thinking of asking, break other algorithms , containers available inside standard namespace? might using assignment operators , copy constructors , happen if delete these explicitly -

// no copy a(const a&) = delete;  // no assign a& operator=(const a&) = delete; 

if not possible, or there's way this, welcome suggestions. thankyou :)

in c++11, requirements types used in containers depend on operations call. thing require unconditionally type erasable, which, when used standard allocator, equivalent requiring p->~t() well-formed , valid.

so, copy-construction required when vector reallocated or copy-construction version of insert used. assignment needed when, example, elements inserted in middle of vector, or container sorted.

for example, here quote http://en.cppreference.com/w/cpp/container/vector on vector:

the requirements imposed on elements depend on actual operations performed on container. generally, required element type complete type , meets requirements of erasable, many member functions impose stricter requirements.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -