[Notes] Effective C ++ 13 (the initialization of the Member initialization in the init list should be the same as the order in t

xiaoxiao2021-03-06  20

#include #include #include using namespace std;

////

Template class array {public: array (int lowbound, int highbound); private: vector data; size_t size; int lbound, hbound;};

// Template // Note 1 (2 line) // Array :: Array (int lowbound, int highbound): size (highbound-lowbound 1), lbound (lowbound), hough (highbound) DATA (size) {}

/// When I use a notes 1, this error occurs when the compiler (VC6.0) is: //libcd.lib (crt0.Obj): Error LNK2001: Unresolved External Symbol _main // debug / initlist. EXE: Fatal Error LNK1120: 1 Unresolved Externals // Error EXECUTING LINK.EXE.///// This is why? // c : Class Member is to initialize // rather than in the order in the Class in the Class, then compile will first initialize Data, and then size, lbound, hbound // I am afraid I can't say something wrong; //

// You may ask why this rule class WACKO {public: WACKO (Const Char * S): S1 (s), S2 (0) {} WACKO (Const Wacko & RHS): S2 (rhs.s1), S1 (0) {} private: STRING S1, S2;}; ///// 00409340 MOV EAX, DWORD PTR [ECX] // 00409342 MOV EDX, 7EFEFFH // 00409347 Add Edx, Eax // 00409349 xor EAX, 0FFH / / 0040934C xor Eax, EDX // 0040934E Add ECX, 4 // 00409351 Test Eax, 81010100H // 00409356 JE main_loop (00409340) // 00409358 MOV EAX, DWORD PTR [ECX-4] // is the assembly code of Strlen / / static size_t __cdecl length (strlen);} // _u _u 0x0000000000 /// DEStructor is // // but if if it is in the reverse order in the constructor Not in the order of initialization, the compiler must track the succession of the Member initialization in each object //, which will bring great costs /

Void main () {WACKO W1 = "Hello World"; WACKO W2 = W1;}

//// Only the initialization of NonStatic Data Member applies this rule // Sitting on the Static Member like Global Object or Namespace Object So you only need to initialize // for Derived Class's base class Data Member, you want to be Derived Class's Data Member // Declaration, multiple inheritance Base Class is initialized to initialize the order of inheritance /// These days are in GIS development, the head is big, or come to see the book better!

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

New Post(0)