Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ rule of five

// Rule of five: When the rule of three deletes the copy constructor or
// assignment operator, the move operators are no longer defined by default.
// If move semantics are desired for the class, they must be specified manually.
class Class {
public:
    Class() {}
    ~Class() { ... }		                // Custom destructor
  
    Class(const Class& c) { ... }	        // Custom copy constructor
  	void operator=(const Class& c) { ... }  // Custom assignment operator
  
    Class(Class&& c) { ... }	        // Custom move constructor
  	void operator=(Class&& c) { ... }   // Custom move assignment operator
private:
    some_type* non_copyable_resource = nullptr;
}
Source by www.fluentcpp.com #
 
PREVIOUS NEXT
Tagged: #rule
ADD COMMENT
Topic
Name
3+6 =