When should you make a class open?

According to the Google Style Guides : "Few classes should be copied. Most should have neither a copy constructor nor an assignment operator."

They recommend that you make the class uncovered (that is, without pointing to the copy constructor or assignment operator) and instead recommend passing it by reference or pointer in most situations or using clone () methods that cannot be called implicitly.

However, I heard some arguments against this:

  • Access to a link is (usually) slower than access to a value.
  • In some calculations, I can leave the original object as it is and simply return the modified object.
  • I might want to save the value of the calculation as a local object in the function and return it, which I could not do if I returned it by reference.
  • If the class is small enough, passing by reference is slower.

What are the positive / negative aspects of this guide? Is there a standard โ€œrule of thumbโ€ to make classes inaccessible? What should be considered when creating new classes?

+4
source share
1 answer

I have two questions with their advice:

  • This does not apply to modern C ++, ignoring the move / assignment operators, and therefore assumes that taking objects by value (which would have been copied earlier) is often inefficient.

  • . , .

, , , , . , std::unique_ptr - , , . , , . .

, , , , , . . , , - , .

, , , - , , :

  • ?
  • ?
  • ?
  • ?

, (, , , ). , - .

++, , . /. , , , - .

, Google , , . . ++.

+6

All Articles