跳到主要內容

發表文章

目前顯示的是 3月, 2010的文章

Static 修飾

用於: 1. Member function (method of Class):     函式裡,包含引數,不能用到 non-static 變數及函式。     沒有 this 指標、函式不能宣告為 const 及 virtual。     其宣告時前面加上 static,若在 Class 作用區域外實作(定義),則不需再加上 static 修飾字,     其於用法限制同一般成員函式。 2. Member variable     只能在 Class 作用區域內宣告,若要給定初值,則需到 Class 作用區域外定義,也是不用     再加上 static 修飾字。 另外整數型 const static 成員較特別,可以直接在 Class 作用區域內給定初值。 static 變數,若只是宣告,且未存取它時,可不用指定初值,compiler 及 linker 可以順利通過,反之,則必需給定一個初值,否則會 linker error。 static variable initialization example: [data type] [class name]:: [static variable name] = [value];

Pointers 指標

對於 const 修飾詞 1. Pointers to const [point to const object of pointers] (指向 const 物件的指標)     // ptr is nonconst pointer and ptr point to const object of double type.     const double *ptr;         ptr 無法知道它所指向的物件是否真的為 const,所以它將它所指向的物件一律視為 const。         這裡有一段話, pointers to const 所指物件並未保證一定不被改變 。     事實上我們可以透過 const pointer 賦予給 nonconst pointer,不過若指向的物件是 const     則一定不會被改變。 2. Const pointers [const of pointers] (本身為 const 的指標)     // ptr is const pointer and ptr point to nonconst object of double type.     double const *ptr;  // 等同 double *const ptr;         如同其它 const 變數一樣,在建立 const pointer 時就該把它初始化。

快速鍵

Eclipse 選取變大寫   [Ctrl] + [Shift] + [x] 選取變小寫   [Ctrl] + [Shift] + [y] 刪除一整行 [Ctrl] + [d] GOTO [Ctrl] + [L] Visual Studio C++ 選取變大寫   [Ctrl] + [Shift] + [u] 選取變小寫   [Ctrl] + [u] 刪除一整行 [Ctrl] + [L]

mount iso file mount -o loop -t iso9660 filename.iso /media/iso mount windows shared folder mount -t cifs //172.20.20.39/temp -o username=linux,password=linux /mnt/ntserver smbmount //172.20.20.39/temp /mnt/ntserver -o username=linux,password=linux 計算目錄大小 du -s directory compare directory diff -r dir1 dir2 PKG_CONFIG_PATH 變數,可自行設定非預設的 *.pc 檔所在路徑。 Update ld.so.cache command /sbin/ldconfig /etc/ld.so.conf 可將非預設的 library 路徑加入此檔,或是改變 LD_LIBRARY_PATH 變數

宣告(Declarations) 和定義(Definitions)

宣告:            1. 可以有 N 個重覆宣告式            2. 讓 Compiler 知道資料型態及變數型態            3. 加上 extern 修飾可以變成單純的宣告式 定義:            1. 只能定義一次            2. 為該變數配置足夠的儲存空間            3. 只要帶了初值,它就是定義式 extern int i;  // 宣告 i,但不定義 i int i;             // 宣告並定義 i extern double pi = 3.1415926; // 定義式 double pi = 3.1415926;            // 也是定義式,且編譯出錯,重覆出現定義式 標頭檔放的是宣告而非定義

win32 sample code

#ifndef UNICODE #define UNICODE #endif #include <windows.h> #include <tchar.h> LRESULT CALLBACK MainWindowProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,                    LPSTR lpCmdLine, int nCmdShow) {     // register windows class     WNDCLASSEX wndclassex = {NULL};     wndclassex.cbSize = sizeof(WNDCLASSEX);     wndclassex.style = CS_HREDRAW | CS_VREDRAW;     wndclassex.lpfnWndProc = MainWindowProc;     //wndclassex.cbClsExtra = 0;     //wndclassex.cbWndExtra = 0;     wndclassex.hInstance = hInstance;     wndclassex.hIcon = LoadIcon(NULL, IDI_APPLICATION);     wndclassex.hCursor = LoadCursor(NULL,IDC_ARROW);     wndclassex.hbrBackground = (HBRUS...