SlideShare una empresa de Scribd logo
1 de 83
Visual Studio 2010 與最新 C++ 整合開發 王建興 技術長 聖藍科技 DEV307
講者簡介 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手機軟體設計競賽第三名
Agenda Visual C++ Projects and the Build System Microsoft Foundation Class (MFC) Library IDE Visual C++ Library C++0x Core Language Features In VC10
Visual C++ Projects and the Build System
MSBuild VCBuild.exe -> MSBuild.exe .vcproj -> .vcxproj .vsprops-> .props
VC++ Directories VC++ directories 設定目前分處兩地 可在 project property 處設定各個專案自己的目錄設定 也可在 Property Manager處設定全域的VC++ directories 設定
Project-to-Project Dependencies 在過去,projects 之間的相依性定義於 solution 檔中 在 VC++ 2010 中,相依性則轉換成為 project-to-project 的參照型式
Custom Build Rules and .rules Files 在過去,自訂規則檔案為附檔名為 .rules 的XML檔案 在 VC++ 2010 中,自訂規則檔案則被拆成 .xml, .props, 以及 .targets 三種檔案
Microsoft Foundation Class (MFC) Library
Windows 7 Features 現在,MFC 支援諸多 Windows 7 的功能,像是 the Ribbon user interface the Taskbar  jump lists  … MFC 自動支援諸多 Windows 7 功能,因此,若要在新的應用程式中使用其他的新功能,使用 MFC Application Wizard 來指定即可
MultiTouch Awareness MFC 讓應用程式得以運用 MultiTouch 使用者介面 MultiTouch 應用程式能處理Windows touch 訊息以及手勢訊息 只需註冊所需事件,作業系統即會將 MultiTouch 事件繞送至你所註冊的事件處理常式
High-DPI Awareness 預設情況下,MFC 應用程式皆為 High-DPI-aware 對 High-DPI-aware 的應用程式來說,作業系統會依據執行時的解析度,將視窗、文字、以及其他的 UI 元素做自動放大縮小 這能使得自動放大縮小後的排版依舊保持正常、不會被截去影像、或者有像素化的情況
Restart Manager Restart Manager 能在您應用程式預期或不預期的關閉或重啟之後,自動儲存文件或是重新應用程式 例如,當您的程式提供了自動更新的機制,那麼,在自動更新完成後,便可運用 Restart Manager 來自動重啟
CTaskDialog CTaskDialog 被可用來取代 AfxMessageBox CTaskDialog 能顯示更多訊息,也能從使用者端回饋更多類資訊
SafeInt Library 新的 SafeInt 程式庫提供了考慮整數運算溢位的運作操作 同時,它也能針對眾多不同類型的整數進行比較
IDE
Improved IntelliSense 舊式的 .ncb ( no compile browse ) 檔被 .sdf ( SQL Server desktop database) 所取代 更快、更精確、更能處理大型專案 當 header 改變時,毋需重新 parse 整個 solution 即使在大型專案中,僅更動小幅度程式碼或切換 build ( Debug -> Release ) 時,速度依舊更快
Improved IntelliSense Errors IDE 更能偵測會引發 IntelliSense 遺失的程式碼 IDE 會將 IntelliSense 的錯誤顯示於 Error List Window
#include Auto-Complete Feature IDE 增加了對 #include 關鍵字的 auto-completion 在輸入 #include 後,IDE 會產生下拉式清單供你挑選可用的 header file 輸入名稱不確定的 header file 時更方便
Navigate To Navigate To 對話窗提供搜尋專案中符合特定字串之所有 symbol 以及檔案的功能 持續輸入搜尋字串,將會立即反映在搜尋結果上
Parallel Debugging and Profiling Visual Studio 的除錯器能在使用 Concurrency Runtime 的情況下協助對平行處理的應用程式進行除錯 新推出的 concurrency profiler 工具也能以視覺化的方式呈現您應用程式整體的效能
Ribbon Designer Ribbon Designer 是讓您透過圖形式方式建立、修改 MFC Ribbon UI 的編輯器 最終的產出是 .mfcribbon-ms 的 XML 資源檔
Call Hierarchy 協助你瀏覽被某一特定函式所呼叫的所有函式或是呼叫該特定函式的所有函式 Call From Call To 取代 Call Browser
Visual C++ Library
Concurrency Runtime Libraries Concurrency Runtime framework 支援以 Visual C++ 開發並行執行的應用程式 Parallel Patterns Library (PPL) 為平行化提供更好的通用性型質的容器以及演算法 Asynchronous Agents Library 則提供了 actor-based 的程式設計模型、訊息傳遞的介面、以及將工作管線化的機制
並行性的例子 int nSum = 0; for(int nNumber=1;nNumber<=100000;++nNumber)    nSum += nNumber; int nSum=0; parallel_for(1, 100001, [&](int n) {    nSum += n;  } ); *Concurrency Runtime 作業系統至少需為 Windows XP SP3
Standard C++ Library(1/2) 在 STL 中使用了新 C++ 語法來實作 move 語義以及完美轉發(perfect forwarding) 利用 rvalue references 來實作新的 unique_ptr class,做為 smart pointer type,更勝 auto_ptr 一籌 共加入了 15 個新函式,像是:find_if_not, copy_if, …
Standard C++ Library(2/2) 新的 make_shared 函式在處理 shared pointer 時更便利、更穩固、也更有效率 新的 cbegin, cend, crbegin 以及 crend 提供對容器正向或反向走訪的 const_iterator exception_ptr class 可被用來在執行緒間傳遞異常
C++0x Core Language Features In VC10
*少林足球中片段
大師兄即將歸位 *少林足球中片段
C++ 王者歸來 *魔戒三部曲海報
何謂 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++
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
C++0x Core Language Features In VC10: The Table (2/3)
C++0x Core Language Features In VC10: The Table (3/3)
今天要談的 C++0x 特色 auto Keyword decltype Type Specifier Lambda Expressions rvalue references static_assert nullptr
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
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.
auto Keyword (3/3) 使用 auto 關鍵字時的重要限制 使用時一定要搭配 initializer 不能用來宣告陣列、變數的 return type、函式或 template 的參數  除了 static member 之外,不能在 class/struct 中使用 auto 宣告 data member
錯誤的 auto 使用 auto a; auto ary[10]; auto ary2[] = { 1, 2, 3} auto foo(); void bar(auto a); struct A {     auto a; };
使用 auto 的時機 當資料型別可能隨著編譯器或目標平台而異時 例 strlen() 的回傳型別 當資料型別過於複雜不易表示時 例 map<int,list<string>>::iterator i  將 Lambdas 指派至變數時 ( 待續,  Lambdas 算式 ) 指定 Trailing Return Types ( 待續, decltype )
auto vs. auto /Zc:auto[-]編譯器選項是用來告訴編譯器看待宣告變數時 auto 這個關鍵字的確切意義 指定 /Zc:auto 編譯器會從所宣告變數的初始算式推導出其確型別 指定 /Zc:auto- 編譯器會以 automatic storage class 來宣告變數 此為相容性問題 *http://msdn.microsoft.com/en-us/library/dd293615.aspx
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
decltype Type Specifier (1/2) decltype 是個 type specifier decltype 依據所給定的算式來決定型別 decltype 不同於 typeid,因為它是從算式中得到型別本身,而非型別資訊 decltype( expression )
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 )
使用 decltype 的時機 適當的表示資料型別 decltype 和 auto 不同的是,auto 推導型別是靠初始算式,得發生指派動作 decltype 只是從算式評估結果的型別來推導型別,但卻不會確切的進行評估 decltype(mstr.begin()->second.get_allocator()) under_alloc; decltype(exit(0)) MyExitFunction(); *http://www.codeproject.com/KB/cpp/cpp10.aspx
trailing-return-type  auto function_name( parameters ) −> decltype( expression ) {   function_body; } template<typename T, typename U> auto myFunc( T& t, U& u)-> decltype( t + u ){   return t + u; };
Lambda Expressions(1/4) 基本上就像是個匿名函式(anonymous function) LambdaExpression 使得函式可以在使用的地方定義,並且可以在Lambda 函式中使用 Lambda 函式之外的變數 比函式物件或函式指標方便且單純 []() mutable throw() -> typeid {   //function body }
Lambda Expressions(2/4) 1.capture clause  2.parameter list  3.mutable specification  4.exception specification 5.return type 6.lambda body
Lambda Expressions (3/4)capture clause *http://heresy.spaces.live.com/blog/cns!E0070FB8ECF9015F!10575.entry
Lambda Expressions (4/4)parameter list 不能有 預設引數 不能有可變長度引數列表 不能有不具名參數 沒有參數時,可省略 parameter list int main() {    int x = 4;    int y = 5;    int z = [=] { return x + y; } ; }
使用函式物件 struct FunctionObj {     void operator()(int n) const { // 操作一下 n     } } … for_each(v.begin(), v.end(), FunctionObj());
使用Lambda Expression for_each(v.begin(), v.end(), [] (int n) { 	// 操作 n }
rvalue references rvalue reference 被創造,其中最大的意義之一,便是為了提供更有效率的 move 語義 rvalue reference 語法 type-id && cast-expression *http://msdn.microsoft.com/en-us/library/dd293668(v=VS.100).aspx
lvalue & rvalue (1/2) 每個算式,若非 lvalue 便為 rvalue lvalue 指的是在單一算式之後所代表的一個續存物件 例:++x rvalue 指的是在算式評估結束之後,生命期便結束的暫時性物件 例:x++ 能對它取址的即為 lvalue *http://blogs.msdn.com/b/vcblog/archive/2009/02/03/rvalue-references-c-0x-features-in-vc10-part-2.aspx
lvalue & rvalue (2/2) string one("cute"); const string two("fluffy"); string three() { return "kittens"; } const string four() { return "are an essential part of a healthy diet"; } one;     // modifiable lvalue two;     // const lvalue three(); // modifiable rvalue four();  // const rvalue
C++ 的複製問題 string s0("my mother told me that"); string s1("cute"); string s2("fluffy"); string s3("kittens"); string s4("are an essential part of a healthy diet"); string dest = s0 + " " + s1 + " " + s2 + " " + s3 + " " + s4; 每次 + 運算子執行時,都會產生一個暫時性物件 產生了八個暫時性物件!
問題出在那裡? 因為 s0 是個 lvalue 不能加以修改,所以在計算 s0 + “ “ 時,得建立一暫時物件 但在接著計算 (s0 + “ ”) + s1 時,可以直接把 s1 接到之前建立的暫時物件後,便毋需再產生第二個暫時物件,並捨棄第一個暫時物件 這便是 move 語義的核心觀念
在 C++0x 中 move 語義的實作 (1/2) 在 C++0x 中,每次 + 運算子被呼叫時,仍會產生獨立的暫時物件 但第二次呼叫 + 運算子時(例如在((s0 + “ ”) + s1)中),會將前一個暫時物件所配置的記憶體挪過來使用 只更動第二個暫時物件指標之值,而不重新配置並複製 第一個暫時物件的指標則指向 null,避免解構時的相關行為
在 C++0x 中 move 語義的實作 (2/2) 所以,若能偵測到處理的是 non-const rvalue 時,就可以直接挪用其記憶體 反正它很快就要被摧毀,又沒人在乎它 從 rvalue 建立物件,或指派 rvalue 物件之值至另一物件時,所謂的 moving,便是挪用其記憶體的動作 例如 vector 要擴展空間時,moving 就很重要
rvalue reference C++0x 引入了名為 rvalue reference 的新 reference,其語法為 Type&& 及 const Type&&  rvalue reference 與 lvalue reference 是不同的型別 但在語意上都一樣是 reference
兩種 reference 在函式重載時的不同行為 Type& 只能繫結到 non-const lvalue  const Type& 可以繫結到任何東西 Type&& 可以繫結到 non-const lvalue 及 non-const rvalue  const Type&& 可以繫結到任何東西
rvalue reference 的overload resolution void purr(const string& s) {     cout << "purr(const string&): " << s << endl; } void purr(string&& s) {     cout << "purr(string&&): " << s << endl; } string strange() {     return "strange()"; } const string charm() {     return "charm()"; } int main() {    string up("up");    const string down("down");    purr(up);			// purr(const string&): up    purr(down);			// purr(const string&): down    purr(strange());			// purr(string&&): strange()    purr(charm());			// purr(const string&): charm()}
提供 move 語義 傳統的 copy 建構子 C++0x 中的 move 建構子 編譯器並不會提供預設的 move 建構子 Simple(const Simple&); Simple(Simple&&); *範例取自 http://www.codeproject.com/KB/cpp/cpp10.aspx#RValues
move 建構子被呼叫 Simple GetSimple() {    Simple sObj(10);    return sObj; }
實作 move 建構子(1/2) class Simple {     // The resource     void* Memory; public:     Simple() { Memory = nullptr; }     // The MOVE-CONSTRUCTOR Simple(Simple&& sObj)     {         // Take ownership         Memory = sObj.Memory;         // Detach ownership         sObj.Memory = nullptr;     } };
實作 move 建構子(2/2) Simple(int nBytes)          {                 Memory = new char[nBytes];          }     ~Simple()     {         if(Memory != nullptr)             delete []Memory;     } };
move 指派運算子 傳統的 copy 指派運算子 C++0x 中的 move 指派運算子 void operator=(const Simple&); void operator=(Simple&&);
實作 move 指派運算子 class Simple {    ...    void operator = (Simple&& sOther)    {        // De-allocate current         delete[] Memory;            // Take other's memory contnent        Memory = sOther.Memory;         // Since we have taken the temporary's resource.        // Detach it!        sOther.Memory = nullptr;    } };};
static_assert Declaration (1/2) 在編譯時期針對指定條件檢驗是否成立 constant-expression: 若值評估為 0,則編譯失敗並顯示string-literal參數之值,反之,則無任何影響 static_assert(      constant-expression,      string-literal  );
static_assert Declaration (2/2) 應用: static_assert(   sizeof(void *)==4,   "64-bit code generation is not supported.");
static_assert 與傳統方式的比較 在過去有兩種檢查方式 條件編譯 + #error 指令 ( 在 preprocessing 階段 ) assert 巨集 ( 在 runtime ) #error 無法針對 template 參數進行檢查,因為 class 是在編譯時才會被 instantiated static_assert 是在編譯時期進行檢查,所以可以處理 template 參數的檢查
nullptr Keyword nullptr 關鍵字用來表示指向空值的指標 解決 0 和指向空值指標的混淆情況 void f(int){ printf( "int" ); }  void f(char*){ printf( "char*" ); }  f( NULL ); // int, compile error in GCC  f( 0 ); // int  f( (char*)0 ); // char*  f( (void*)0 ); // compile error  *http://heresy.spaces.live.com/blog/cns!E0070FB8ECF9015F!10891.entry
Q & A
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
請協助完成「本課程問卷」,並在離開教室時交給工作人員! 填妥大會背包中的大會問卷,可於活動第三天兌換問卷禮哦! 感謝您的合作。
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation.  Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.  MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Más contenido relacionado

La actualidad más candente

07 陣列與字串
07 陣列與字串07 陣列與字串
07 陣列與字串
shademoon
 
C語言 第4章 基本輸出與輸入功能
C語言 第4章 基本輸出與輸入功能C語言 第4章 基本輸出與輸入功能
C語言 第4章 基本輸出與輸入功能
shademoon
 
第六章 函數與巨集
第六章 函數與巨集第六章 函數與巨集
第六章 函數與巨集
shademoon
 
Scala function-and-closures
Scala function-and-closuresScala function-and-closures
Scala function-and-closures
wang hongjiang
 
OOP in C - Virtual Function (Chinese Version)
OOP in C - Virtual Function (Chinese Version)OOP in C - Virtual Function (Chinese Version)
OOP in C - Virtual Function (Chinese Version)
Kai-Feng Chou
 
C++中级培训胶片
C++中级培训胶片C++中级培训胶片
C++中级培训胶片
ff1
 
Ecma script edition5-小试
Ecma script edition5-小试Ecma script edition5-小试
Ecma script edition5-小试
lydiafly
 

La actualidad más candente (20)

Java Script 引擎技术
Java Script 引擎技术Java Script 引擎技术
Java Script 引擎技术
 
07 陣列與字串
07 陣列與字串07 陣列與字串
07 陣列與字串
 
08 指標
08 指標08 指標
08 指標
 
Ch08
Ch08Ch08
Ch08
 
C語言 第4章 基本輸出與輸入功能
C語言 第4章 基本輸出與輸入功能C語言 第4章 基本輸出與輸入功能
C語言 第4章 基本輸出與輸入功能
 
第六章 函數與巨集
第六章 函數與巨集第六章 函數與巨集
第六章 函數與巨集
 
Scala function-and-closures
Scala function-and-closuresScala function-and-closures
Scala function-and-closures
 
functional-scala
functional-scalafunctional-scala
functional-scala
 
OOP in C - Virtual Function (Chinese Version)
OOP in C - Virtual Function (Chinese Version)OOP in C - Virtual Function (Chinese Version)
OOP in C - Virtual Function (Chinese Version)
 
Programming in Objective-C
Programming in Objective-CProgramming in Objective-C
Programming in Objective-C
 
C++中级培训胶片
C++中级培训胶片C++中级培训胶片
C++中级培训胶片
 
Ecma script edition5-小试
Ecma script edition5-小试Ecma script edition5-小试
Ecma script edition5-小试
 
Python基本資料運算
Python基本資料運算Python基本資料運算
Python基本資料運算
 
getPDF.aspx
getPDF.aspxgetPDF.aspx
getPDF.aspx
 
Python分支作業
Python分支作業Python分支作業
Python分支作業
 
C++11 smart pointers
C++11 smart pointersC++11 smart pointers
C++11 smart pointers
 
Ch01
Ch01Ch01
Ch01
 
JavaScript 教程
JavaScript 教程JavaScript 教程
JavaScript 教程
 
Python 迴圈作業
Python 迴圈作業Python 迴圈作業
Python 迴圈作業
 
Ch 8
Ch 8Ch 8
Ch 8
 

Similar a Dev307

TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
Will Huang
 
Struts Mitac(1)
Struts Mitac(1)Struts Mitac(1)
Struts Mitac(1)
wangjiaz
 
C++工程实践
C++工程实践C++工程实践
C++工程实践
Shuo Chen
 
Metro Style Apps from C++ Developers' View
Metro Style Apps from C++ Developers' ViewMetro Style Apps from C++ Developers' View
Metro Style Apps from C++ Developers' View
Eric ShangKuan
 
Struts学习笔记
Struts学习笔记Struts学习笔记
Struts学习笔记
yiditushe
 
Introduction To Direct Show
Introduction To Direct ShowIntroduction To Direct Show
Introduction To Direct Show
guestce3937
 
Introduction To Direct Show
Introduction To  Direct ShowIntroduction To  Direct Show
Introduction To Direct Show
guestce3937
 
信息系统开发平台OpenExpressApp
信息系统开发平台OpenExpressApp信息系统开发平台OpenExpressApp
信息系统开发平台OpenExpressApp
zhoujg
 
Lotus domino开发教程
Lotus domino开发教程Lotus domino开发教程
Lotus domino开发教程
dyzm_2000
 

Similar a Dev307 (20)

TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
 
ES5 introduction
ES5 introductionES5 introduction
ES5 introduction
 
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
 
Struts Mitac(1)
Struts Mitac(1)Struts Mitac(1)
Struts Mitac(1)
 
getPDF.aspx
getPDF.aspxgetPDF.aspx
getPDF.aspx
 
千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7
 
C++工程实践
C++工程实践C++工程实践
C++工程实践
 
VC++ Programming Training Lecture in Control Lab 301 of YSU
VC++ Programming Training Lecture in Control Lab 301 of YSUVC++ Programming Training Lecture in Control Lab 301 of YSU
VC++ Programming Training Lecture in Control Lab 301 of YSU
 
Metro Style Apps from C++ Developers' View
Metro Style Apps from C++ Developers' ViewMetro Style Apps from C++ Developers' View
Metro Style Apps from C++ Developers' View
 
ajax_onlinemad
ajax_onlinemadajax_onlinemad
ajax_onlinemad
 
Struts学习笔记
Struts学习笔记Struts学习笔记
Struts学习笔记
 
Introduction To Direct Show
Introduction To Direct ShowIntroduction To Direct Show
Introduction To Direct Show
 
Introduction To Direct Show
Introduction To  Direct ShowIntroduction To  Direct Show
Introduction To Direct Show
 
为实时机器学习设计的算法接口与迭代引擎_FFA_2021
为实时机器学习设计的算法接口与迭代引擎_FFA_2021为实时机器学习设计的算法接口与迭代引擎_FFA_2021
为实时机器学习设计的算法接口与迭代引擎_FFA_2021
 
Inside VCL
Inside VCLInside VCL
Inside VCL
 
信息系统开发平台OpenExpressApp
信息系统开发平台OpenExpressApp信息系统开发平台OpenExpressApp
信息系统开发平台OpenExpressApp
 
软件工程
软件工程软件工程
软件工程
 
Uml
UmlUml
Uml
 
Js培训
Js培训Js培训
Js培训
 
Lotus domino开发教程
Lotus domino开发教程Lotus domino开发教程
Lotus domino开发教程
 

Más de 建興 王 (11)

全文搜尋引擎的進階實作與應用
全文搜尋引擎的進階實作與應用全文搜尋引擎的進階實作與應用
全文搜尋引擎的進階實作與應用
 
排隊應用開發
排隊應用開發排隊應用開發
排隊應用開發
 
「沙中撈金術」﹣談開放原始碼的推薦系統
「沙中撈金術」﹣談開放原始碼的推薦系統 「沙中撈金術」﹣談開放原始碼的推薦系統
「沙中撈金術」﹣談開放原始碼的推薦系統
 
Windows Mobile 多媒體應用程式開發
Windows Mobile 多媒體應用程式開發Windows Mobile 多媒體應用程式開發
Windows Mobile 多媒體應用程式開發
 
開放原始碼的回收與再利用
開放原始碼的回收與再利用開放原始碼的回收與再利用
開放原始碼的回收與再利用
 
lwdba – 開放原始碼的輕量級資料庫存取程式庫
lwdba – 開放原始碼的輕量級資料庫存取程式庫lwdba – 開放原始碼的輕量級資料庫存取程式庫
lwdba – 開放原始碼的輕量級資料庫存取程式庫
 
IKVM.NET 深入敵營的 Java
IKVM.NET 深入敵營的 JavaIKVM.NET 深入敵營的 Java
IKVM.NET 深入敵營的 Java
 
Java 的開放原碼全文搜尋技術 - Lucene
Java 的開放原碼全文搜尋技術 - LuceneJava 的開放原碼全文搜尋技術 - Lucene
Java 的開放原碼全文搜尋技術 - Lucene
 
開發實用創新的 Android 應用程式
開發實用創新的 Android 應用程式開發實用創新的 Android 應用程式
開發實用創新的 Android 應用程式
 
從 Java programmer 的觀點看 ruby
從 Java programmer 的觀點看 ruby從 Java programmer 的觀點看 ruby
從 Java programmer 的觀點看 ruby
 
在雲端上啜飲爪哇
在雲端上啜飲爪哇在雲端上啜飲爪哇
在雲端上啜飲爪哇
 

Dev307

  • 1.
  • 2. Visual Studio 2010 與最新 C++ 整合開發 王建興 技術長 聖藍科技 DEV307
  • 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
  • 5. Visual C++ Projects and the Build System
  • 6. MSBuild VCBuild.exe -> MSBuild.exe .vcproj -> .vcxproj .vsprops-> .props
  • 7. VC++ Directories VC++ directories 設定目前分處兩地 可在 project property 處設定各個專案自己的目錄設定 也可在 Property Manager處設定全域的VC++ directories 設定
  • 8.
  • 9. Project-to-Project Dependencies 在過去,projects 之間的相依性定義於 solution 檔中 在 VC++ 2010 中,相依性則轉換成為 project-to-project 的參照型式
  • 10. Custom Build Rules and .rules Files 在過去,自訂規則檔案為附檔名為 .rules 的XML檔案 在 VC++ 2010 中,自訂規則檔案則被拆成 .xml, .props, 以及 .targets 三種檔案
  • 11. Microsoft Foundation Class (MFC) Library
  • 12. Windows 7 Features 現在,MFC 支援諸多 Windows 7 的功能,像是 the Ribbon user interface the Taskbar jump lists … MFC 自動支援諸多 Windows 7 功能,因此,若要在新的應用程式中使用其他的新功能,使用 MFC Application Wizard 來指定即可
  • 13. MultiTouch Awareness MFC 讓應用程式得以運用 MultiTouch 使用者介面 MultiTouch 應用程式能處理Windows touch 訊息以及手勢訊息 只需註冊所需事件,作業系統即會將 MultiTouch 事件繞送至你所註冊的事件處理常式
  • 14. High-DPI Awareness 預設情況下,MFC 應用程式皆為 High-DPI-aware 對 High-DPI-aware 的應用程式來說,作業系統會依據執行時的解析度,將視窗、文字、以及其他的 UI 元素做自動放大縮小 這能使得自動放大縮小後的排版依舊保持正常、不會被截去影像、或者有像素化的情況
  • 15. Restart Manager Restart Manager 能在您應用程式預期或不預期的關閉或重啟之後,自動儲存文件或是重新應用程式 例如,當您的程式提供了自動更新的機制,那麼,在自動更新完成後,便可運用 Restart Manager 來自動重啟
  • 16. CTaskDialog CTaskDialog 被可用來取代 AfxMessageBox CTaskDialog 能顯示更多訊息,也能從使用者端回饋更多類資訊
  • 17. SafeInt Library 新的 SafeInt 程式庫提供了考慮整數運算溢位的運作操作 同時,它也能針對眾多不同類型的整數進行比較
  • 18. IDE
  • 19. Improved IntelliSense 舊式的 .ncb ( no compile browse ) 檔被 .sdf ( SQL Server desktop database) 所取代 更快、更精確、更能處理大型專案 當 header 改變時,毋需重新 parse 整個 solution 即使在大型專案中,僅更動小幅度程式碼或切換 build ( Debug -> Release ) 時,速度依舊更快
  • 20. Improved IntelliSense Errors IDE 更能偵測會引發 IntelliSense 遺失的程式碼 IDE 會將 IntelliSense 的錯誤顯示於 Error List Window
  • 21. #include Auto-Complete Feature IDE 增加了對 #include 關鍵字的 auto-completion 在輸入 #include 後,IDE 會產生下拉式清單供你挑選可用的 header file 輸入名稱不確定的 header file 時更方便
  • 22.
  • 23. Navigate To Navigate To 對話窗提供搜尋專案中符合特定字串之所有 symbol 以及檔案的功能 持續輸入搜尋字串,將會立即反映在搜尋結果上
  • 24.
  • 25. Parallel Debugging and Profiling Visual Studio 的除錯器能在使用 Concurrency Runtime 的情況下協助對平行處理的應用程式進行除錯 新推出的 concurrency profiler 工具也能以視覺化的方式呈現您應用程式整體的效能
  • 26. Ribbon Designer Ribbon Designer 是讓您透過圖形式方式建立、修改 MFC Ribbon UI 的編輯器 最終的產出是 .mfcribbon-ms 的 XML 資源檔
  • 28.
  • 30. Concurrency Runtime Libraries Concurrency Runtime framework 支援以 Visual C++ 開發並行執行的應用程式 Parallel Patterns Library (PPL) 為平行化提供更好的通用性型質的容器以及演算法 Asynchronous Agents Library 則提供了 actor-based 的程式設計模型、訊息傳遞的介面、以及將工作管線化的機制
  • 31. 並行性的例子 int nSum = 0; for(int nNumber=1;nNumber<=100000;++nNumber) nSum += nNumber; int nSum=0; parallel_for(1, 100001, [&](int n) { nSum += n; } ); *Concurrency Runtime 作業系統至少需為 Windows XP SP3
  • 32. Standard C++ Library(1/2) 在 STL 中使用了新 C++ 語法來實作 move 語義以及完美轉發(perfect forwarding) 利用 rvalue references 來實作新的 unique_ptr class,做為 smart pointer type,更勝 auto_ptr 一籌 共加入了 15 個新函式,像是:find_if_not, copy_if, …
  • 33. Standard C++ Library(2/2) 新的 make_shared 函式在處理 shared pointer 時更便利、更穩固、也更有效率 新的 cbegin, cend, crbegin 以及 crend 提供對容器正向或反向走訪的 const_iterator exception_ptr class 可被用來在執行緒間傳遞異常
  • 34. C++0x Core Language Features In VC10
  • 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
  • 40. C++0x Core Language Features In VC10: The Table (2/3)
  • 41. C++0x Core Language Features In VC10: The Table (3/3)
  • 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; };
  • 47. 使用 auto 的時機 當資料型別可能隨著編譯器或目標平台而異時 例 strlen() 的回傳型別 當資料型別過於複雜不易表示時 例 map<int,list<string>>::iterator i 將 Lambdas 指派至變數時 ( 待續, Lambdas 算式 ) 指定 Trailing Return Types ( 待續, decltype )
  • 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 )
  • 52. 使用 decltype 的時機 適當的表示資料型別 decltype 和 auto 不同的是,auto 推導型別是靠初始算式,得發生指派動作 decltype 只是從算式評估結果的型別來推導型別,但卻不會確切的進行評估 decltype(mstr.begin()->second.get_allocator()) under_alloc; decltype(exit(0)) MyExitFunction(); *http://www.codeproject.com/KB/cpp/cpp10.aspx
  • 53. trailing-return-type auto function_name( parameters ) −> decltype( expression ) { function_body; } template<typename T, typename U> auto myFunc( T& t, U& u)-> decltype( t + u ){ return t + u; };
  • 54. Lambda Expressions(1/4) 基本上就像是個匿名函式(anonymous function) LambdaExpression 使得函式可以在使用的地方定義,並且可以在Lambda 函式中使用 Lambda 函式之外的變數 比函式物件或函式指標方便且單純 []() mutable throw() -> typeid { //function body }
  • 55. Lambda Expressions(2/4) 1.capture clause 2.parameter list 3.mutable specification 4.exception specification 5.return type 6.lambda body
  • 56. Lambda Expressions (3/4)capture clause *http://heresy.spaces.live.com/blog/cns!E0070FB8ECF9015F!10575.entry
  • 57. Lambda Expressions (4/4)parameter list 不能有 預設引數 不能有可變長度引數列表 不能有不具名參數 沒有參數時,可省略 parameter list int main() { int x = 4; int y = 5; int z = [=] { return x + y; } ; }
  • 58. 使用函式物件 struct FunctionObj { void operator()(int n) const { // 操作一下 n } } … for_each(v.begin(), v.end(), FunctionObj());
  • 59. 使用Lambda Expression for_each(v.begin(), v.end(), [] (int n) { // 操作 n }
  • 60. rvalue references rvalue reference 被創造,其中最大的意義之一,便是為了提供更有效率的 move 語義 rvalue reference 語法 type-id && cast-expression *http://msdn.microsoft.com/en-us/library/dd293668(v=VS.100).aspx
  • 61. lvalue & rvalue (1/2) 每個算式,若非 lvalue 便為 rvalue lvalue 指的是在單一算式之後所代表的一個續存物件 例:++x rvalue 指的是在算式評估結束之後,生命期便結束的暫時性物件 例:x++ 能對它取址的即為 lvalue *http://blogs.msdn.com/b/vcblog/archive/2009/02/03/rvalue-references-c-0x-features-in-vc10-part-2.aspx
  • 62. lvalue & rvalue (2/2) string one("cute"); const string two("fluffy"); string three() { return "kittens"; } const string four() { return "are an essential part of a healthy diet"; } one; // modifiable lvalue two; // const lvalue three(); // modifiable rvalue four(); // const rvalue
  • 63. C++ 的複製問題 string s0("my mother told me that"); string s1("cute"); string s2("fluffy"); string s3("kittens"); string s4("are an essential part of a healthy diet"); string dest = s0 + " " + s1 + " " + s2 + " " + s3 + " " + s4; 每次 + 運算子執行時,都會產生一個暫時性物件 產生了八個暫時性物件!
  • 64. 問題出在那裡? 因為 s0 是個 lvalue 不能加以修改,所以在計算 s0 + “ “ 時,得建立一暫時物件 但在接著計算 (s0 + “ ”) + s1 時,可以直接把 s1 接到之前建立的暫時物件後,便毋需再產生第二個暫時物件,並捨棄第一個暫時物件 這便是 move 語義的核心觀念
  • 65. 在 C++0x 中 move 語義的實作 (1/2) 在 C++0x 中,每次 + 運算子被呼叫時,仍會產生獨立的暫時物件 但第二次呼叫 + 運算子時(例如在((s0 + “ ”) + s1)中),會將前一個暫時物件所配置的記憶體挪過來使用 只更動第二個暫時物件指標之值,而不重新配置並複製 第一個暫時物件的指標則指向 null,避免解構時的相關行為
  • 66. 在 C++0x 中 move 語義的實作 (2/2) 所以,若能偵測到處理的是 non-const rvalue 時,就可以直接挪用其記憶體 反正它很快就要被摧毀,又沒人在乎它 從 rvalue 建立物件,或指派 rvalue 物件之值至另一物件時,所謂的 moving,便是挪用其記憶體的動作 例如 vector 要擴展空間時,moving 就很重要
  • 67. rvalue reference C++0x 引入了名為 rvalue reference 的新 reference,其語法為 Type&& 及 const Type&& rvalue reference 與 lvalue reference 是不同的型別 但在語意上都一樣是 reference
  • 68. 兩種 reference 在函式重載時的不同行為 Type& 只能繫結到 non-const lvalue const Type& 可以繫結到任何東西 Type&& 可以繫結到 non-const lvalue 及 non-const rvalue const Type&& 可以繫結到任何東西
  • 69. rvalue reference 的overload resolution void purr(const string& s) { cout << "purr(const string&): " << s << endl; } void purr(string&& s) { cout << "purr(string&&): " << s << endl; } string strange() { return "strange()"; } const string charm() { return "charm()"; } int main() { string up("up"); const string down("down"); purr(up); // purr(const string&): up purr(down); // purr(const string&): down purr(strange()); // purr(string&&): strange() purr(charm()); // purr(const string&): charm()}
  • 70. 提供 move 語義 傳統的 copy 建構子 C++0x 中的 move 建構子 編譯器並不會提供預設的 move 建構子 Simple(const Simple&); Simple(Simple&&); *範例取自 http://www.codeproject.com/KB/cpp/cpp10.aspx#RValues
  • 71. move 建構子被呼叫 Simple GetSimple() { Simple sObj(10); return sObj; }
  • 72. 實作 move 建構子(1/2) class Simple { // The resource void* Memory; public: Simple() { Memory = nullptr; } // The MOVE-CONSTRUCTOR Simple(Simple&& sObj) { // Take ownership Memory = sObj.Memory; // Detach ownership sObj.Memory = nullptr; } };
  • 73. 實作 move 建構子(2/2) Simple(int nBytes) { Memory = new char[nBytes]; } ~Simple() { if(Memory != nullptr) delete []Memory; } };
  • 74. move 指派運算子 傳統的 copy 指派運算子 C++0x 中的 move 指派運算子 void operator=(const Simple&); void operator=(Simple&&);
  • 75. 實作 move 指派運算子 class Simple { ... void operator = (Simple&& sOther) { // De-allocate current delete[] Memory; // Take other's memory contnent Memory = sOther.Memory; // Since we have taken the temporary's resource. // Detach it! sOther.Memory = nullptr; } };};
  • 76. static_assert Declaration (1/2) 在編譯時期針對指定條件檢驗是否成立 constant-expression: 若值評估為 0,則編譯失敗並顯示string-literal參數之值,反之,則無任何影響 static_assert( constant-expression, string-literal );
  • 77. static_assert Declaration (2/2) 應用: static_assert( sizeof(void *)==4, "64-bit code generation is not supported.");
  • 78. static_assert 與傳統方式的比較 在過去有兩種檢查方式 條件編譯 + #error 指令 ( 在 preprocessing 階段 ) assert 巨集 ( 在 runtime ) #error 無法針對 template 參數進行檢查,因為 class 是在編譯時才會被 instantiated static_assert 是在編譯時期進行檢查,所以可以處理 template 參數的檢查
  • 79. nullptr Keyword nullptr 關鍵字用來表示指向空值的指標 解決 0 和指向空值指標的混淆情況 void f(int){ printf( "int" ); } void f(char*){ printf( "char*" ); } f( NULL ); // int, compile error in GCC f( 0 ); // int f( (char*)0 ); // char* f( (void*)0 ); // compile error *http://heresy.spaces.live.com/blog/cns!E0070FB8ECF9015F!10891.entry
  • 80. Q & A
  • 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
  • 83. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.