当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

《The C++ Programming Language》课程教学资源(PPT课件讲稿)Lecture 01 From C to C++

资源类别:文库,文档格式:PPT,文档页数:42,文件大小:632.5KB,团购合买
点击下载完整版文档(PPT)

The c ++ Programming Language Lecture 1 From c to c++

The C++ Programming Language Lecture 1: From C to C++

Brief introduction Requirements

Brief Introduction & Requirements

Coding Style Requirements - Naming Conventions Hungarian Notation o IGlobalPrefix[TypePrefix]-BaseTag-Name [GlobalPrefix] C++ member variables start with: m Global variables start with: g Static data members start with Classes start with: C Interfaces start with: I Standard [PrefIX: A pointer. CHAR* psz g An array. DWORD rgfype[.]i pp-A pointer to a pointer. int* ppTop i h -a handle. HANdle hFile ref -A reference to. char Func(string& refResult

Coding Style Requirements -- Naming Conventions ◼ Hungarian Notation ◼ [GlobalPrefix][TypePrefix]-BaseTag-Name ◼ [GlobalPrefix] ◼ C++ member variables start with: m_ ◼ Global variables start with: g_ ◼ Static data members start with: s_ ◼ Classes start with: C ◼ Interfaces start with: I ◼ Standard [Prefix]: p – A pointer. CHAR* psz; rg – An array. DWORD rgType[…]; pp – A pointer to a pointer. int* ppTop; h – A handle. HANDLE hFile; ref – A reference to. char Func(string& refResult);

Coding Style Requirements Naming Conventions(cont) Standard“ BaseTag” void BOOL BYTE vfbd UINT >1i CHAR Double float fl WCHAR wch ULONG >u1 LONG NOI dw HRESULT hr function Name-Meaningful and Capitalizing every word NULL str USHORT, SHORT, WORD ■ Example m_pdTopofstack CTypelib -g_fSwitchForDest s SZStartingURL

Coding Style Requirements -- Naming Conventions (cont.) ◼ Standard “BaseTag” void -> v int -> i BOOL -> f UINT -> ui BYTE -> b CHAR -> ch Double -> d float -> fl WCHAR -> wch ULONG -> ul LONG -> l DWORD -> dw HRESULT -> hr fn -> function sz -> NULL str USHORT, SHORT, WORD -> w ◼ Name – Meaningful and Capitalizing every words ◼ Example ◼ m_pdTopOfStack ◼ CTypeLib ◼ g_fSwitchForDest ◼ s_szStartingURL

Coding Style Requirements Naming Conventions(cont) Let 's have some tries A flag indicates whether a C++ object has been initialized BOOL m iNitialized A Session id: dWord dwsessionID a Pointer to byte buffer BYTE* pbBuffer a global buffer to store logfile filename CHAR g SZLOgEile [MAX NUM] a pointer to a global logfile name CHAR* g ps lOgfIle;

Coding Style Requirements -- Naming Conventions (cont.) ◼ Let’s have some tries… ◼ A flag indicates whether a C++ object has been initialized: ◼ BOOL m_fInitialized; ◼ A Session ID: ◼ DWORD dwSessionID; ◼ A Pointer to BYTE buffer: ◼ BYTE* pbBuffer; ◼ A global buffer to store logfile filename: ◼ CHAR g_szLogFile[MAX_NUM]; ◼ A pointer to a global logfile name: ◼ CHAR* g_pszLogFile;

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() { … }

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共42页,可试读14页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有