Coding Style Requirements Code Indentation 4 spaces per indent level Braces in Statements Class EXample While( foo) public / /member functions declaration if(NULl = bar) Example( w Example Funcl(ad) private #ifdef DEBUG els void Trace Value( int iValue ) #endif Func2 (bc) Func30;
Coding Style Requirements -- Code Indentation ◼ 4 spaces per indent level Class CExample { public: //member functions declaration Cexample(); ~Cexample(); private: #ifdef _DEBUG void TraceValue( int iValue ); #endif … }; While (foo) { if (NULL == bar) { Func1(ad); } else { Func2(bc); } Func3(); } ◼ Braces in Statements
Useful Concepts Review
Useful Concepts Review
Reviewing c in C++ int functionA(int iX, int iY); int functionA(int iX, int iIi functionA 3,5) The first is a declaration the second is a definition (with null statements), the third is an invoking a Declaration of a variable or function can appear many times, while definition only once iX ir- parameters,3&5- arguments
Reviewing C in C++ int functionA(int iX, int iY); int functionA(int iX, int iY) {}; functionA(3,5); ◼ The first is a declaration, the second is a definition (with null statements), the third is an invoking ◼ Declaration of a variable or function can appear many times, while definition only once ◼ iX & iY - parameters, 3 & 5 - arguments
Reviewing C in C++(cont) int iX extern int ix: int function; extern int function BO; Keyword extern? means it is only a declaration, its definition is later or external to this file, asking the compiler not to assign memory or generate code extern int functionB0ti//---invalid
Reviewing C in C++ (cont.) int iX; extern int iX; int functionB(); extern int functionB(); ◼ Keyword ‘extern’ means it is only a declaration, its definition is later or external to this file, asking the compiler not to assign memory or generate code ◼ extern int functionB() {}; //---invalid
Reviewing C in C++(cont) int funCAO static intⅸ=0 int funCAO static intⅸ=0 a Function can" remember >> ix is a local oloba/ i between calls variable” to the file But iX is unavailable Its scope is only in outside the function its this file scope is in this function
Reviewing C in C++ (cont.) int funcA() { static int iX = 0; } ◼ iX is a “local global variable” to the file ◼ Its scope is only in this file ◼ Function can “remember ” iX between calls ◼ But iX is unavailable outside the function, its scope is in this function static int iX = 0; int funcA() { … }