FWD: from Jjhou's Web

xiaoxiao2021-03-06  59

A little thing

> The same class: >> Class Array {> public:> int a [2];> array update () {> a [0] = a [0] * 3;> a [1] = a [1] * 3;> Return (* this);}>}; >> Two different main: >> main ()> {> array n;> Na [0] = 1; Na [1] = 2;> n. Update ();> na [0] = 0;> cout << Na [0] << endl << Na [1] << endl;>} >> main ()> {> array n;> na [0 ] = 1; Na [1] = 2;> (n.Update ()). A [0] = 0; // Two lines merge into one line> COUT << Na [0] << Endl << NA [1 ] << Endl;>} That too much writing problem: a. Effctive C : Terms 20: Avoid adding Data Members in an open interface Item 20: Avoid Data Members in the public interface.b. Effctive C : Terms 22: Try to Using Pass-by-Reference (inlet), less pass-by-value (pass value) Item 22: prefer pass-by-reference to pass-by-value.c. Effctive C : Terms 29: Avoid back internal Information about Handlesitem 29: Avoid Returning "Handles" to Internal Data.D. More Effctive C : Terms 19: Understanding the Source of Temporary Parts Item 19: Understand The Origin of Temporary Objectse. More Effctive C : Terms 22: Consider composite operations Sub OP = Replace Single Operator Opitem 22: Consider Using Op = INSTEAD OF STAND-Alone OP

转载请注明原文地址:https://www.9cbs.com/read-112894.html

New Post(0)