3. 講者簡介 Education Ph.D. Candidate, Department of Computer Science, National Tsing-Hua University, Taiwan Research interests: distribute network management, mobile agent, VoIP, and p2p networking, sensor network Book Translation Thinking in Java 4nd Edition, in Traditional Chinese Thinking in Java 2nd Edition, in Traditional Chinese Essential C++, in Traditional Chinese 專欄 iTHome 電腦報程式人專欄 Honor The champion of the Trend Micro Programming Contest 2004 2009通訊大賽-Android手機軟體設計競賽第三名
4. Agenda Visual C++ Projects and the Build System Microsoft Foundation Class (MFC) Library IDE Visual C++ Library C++0x Core Language Features In VC10
12. Windows 7 Features 現在,MFC 支援諸多 Windows 7 的功能,像是 the Ribbon user interface the Taskbar jump lists … MFC 自動支援諸多 Windows 7 功能,因此,若要在新的應用程式中使用其他的新功能,使用 MFC Application Wizard 來指定即可
38. 何謂 C++0x 目前一般所使用的 C++ 語法標準,實際上大部分應該都是所謂 C++98 / C++03 的 ISO/IEC 14882:1998、ISO/IEC 14882:2003 尚在草案階段的 C++0x ( 讀音:see plus plus oh ex ) 則是 C++ 語言的新標準 Bjarne Stroustrup 宣稱 C++0x 將會近乎 100% 相容於現有的標準 C++
39. C++0x Core Language Features In VC10: The Table (1/3) *http://blogs.msdn.com/b/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx
42. 今天要談的 C++0x 特色 auto Keyword decltype Type Specifier Lambda Expressions rvalue references static_assert nullptr
43. auto Keyword (1/3) auto 關鍵字能從所宣告變數的初始算式,導出其型別 ( 當然是編譯時期 ) auto declarator initializer; int j = 0; auto k = 0; // Variable k is implicitly type int *http://msdn.microsoft.com/en-us/library/dd293667(v=VS.100).aspx
44. auto Keyword (2/3) map<int,list<string>>::iterator i = m.begin(); auto i = m.begin(); auto x = 1, *y = &x, **z = &y; // Resolves to int. auto a(2.01), *b (&a); // Resolves to double. auto c = 'a', *d(&c); // Resolves to char. auto m = 1, &n = m; // Resolves to int.
45. auto Keyword (3/3) 使用 auto 關鍵字時的重要限制 使用時一定要搭配 initializer 不能用來宣告陣列、變數的 return type、函式或 template 的參數 除了 static member 之外,不能在 class/struct 中使用 auto 宣告 data member
46. 錯誤的 auto 使用 auto a; auto ary[10]; auto ary2[] = { 1, 2, 3} auto foo(); void bar(auto a); struct A { auto a; };
48. auto vs. auto /Zc:auto[-]編譯器選項是用來告訴編譯器看待宣告變數時 auto 這個關鍵字的確切意義 指定 /Zc:auto 編譯器會從所宣告變數的初始算式推導出其確型別 指定 /Zc:auto- 編譯器會以 automatic storage class 來宣告變數 此為相容性問題 *http://msdn.microsoft.com/en-us/library/dd293615.aspx
49. const_iterator 的加強 for(vector<string>::const_iterator iter = Strings.begin(); iter != Strings.end(); ++iter) { std::cout << *iter << std::endl; } for(auto iter = Strings.cbegin(); iter!=Strings.cend(); ++iter) {...} *http://www.codeproject.com/KB/cpp/cpp10.aspx
50. decltype Type Specifier (1/2) decltype 是個 type specifier decltype 依據所給定的算式來決定型別 decltype 不同於 typeid,因為它是從算式中得到型別本身,而非型別資訊 decltype( expression )
51. decltype Type Specifier (2/2) int var; const int&& fx(); struct A { double x; } const A* a = new A(); decltype(fx()); // const int && decltype(var) // int decltype(a->x) // double ( The type of the member access ) decltype((a->x)) // const double && (an expression instead of a member access )
57. Lambda Expressions (4/4)parameter list 不能有 預設引數 不能有可變長度引數列表 不能有不具名參數 沒有參數時,可省略 parameter list int main() { int x = 4; int y = 5; int z = [=] { return x + y; } ; }
81. http://technet.microsoft.com/zh-tw/default.aspx Resources for IT Professionals http://msdn.microsoft.com/zh-tw/default.aspx Resources for Developers http://blogs.msdn.com/b/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx C++0x Core Language Features In VC10: The Table 其他資源 http://heresy.spaces.live.com/blog/cns!E0070FB8ECF9015F!10386.entryC++ 語法再加強:C++0x http://endlesschildhood.blogspot.com/2009/03/rvalue-references-c0x-features-in-vc10.html Rvalue References: C++0x Features in VC10, Part 2