| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c/c++ >> C++/CLI shi zhan ——HELLO

C++/CLI shi zhan ——HELLO

2008-06-01 02:07:28 编辑來源:互联网 评论
 
 
 
本文为【C++/CLI实战——HELLO】的拼音翻译版
  shen me shi C++/CLI? C++/CLI miao hui de shi yi zhong duo yuan zu he , ci chu de C++ dang ran shi zhi Bjarne Stroustrup zai Bell shi yan shi fa ming de C++ bian cheng yu yan 。 ta zhi chi su du he zhi xing wen jian de da xiao dou de dao you hua de jing tai dui xiang mo xing 。 dan chu le dui nei cun fen pei yi wai , ta bu zhi chi yun xing shi cheng xu dui dui xiang de geng gai 。 ta da ying dui di ceng ji qi jin xing wu xian zhi de fang wen , dan dui yu zheng zai yun xing de cheng xu zhong de huo dong lei xing 、 yi ji xiang guan de cheng xu ji chu gou zao , ta de fang wen neng li que fei chang you xian 、 huo zhe gen ben jiu bu ke neng 。 wo zai wei ruan de tong shi Herb Sutter, ye shi C++/CLI de zhu jia gou shi , ren wei C++ shi yi ge hun ning tu yu yan 。
  “CLI” ji gong gong yu yan ji chu jie gou (Common Language InfrastrUCture), zhe shi yi ge zhi chi dong tai zu jian bian cheng mo xing de duo ceng jia gou 。 zai xu duo fang mian , ta suo biao shi de dui xiang mo xing he C++ de wan quan xiang fan 。 ta shi yi ge yun xing shi ruan jian ceng , yi ge xu ni zhi xing xi tong , yun xing zai ying yong cheng xu he di ceng cao zuo xi tong zhi jian 。 dui di ceng ji qi de fang wen shou dao xiang dang yan ge de xian zhi 。 zhi chi dui yun xing zhong cheng xu de huo dong lei xing yi ji guan lian cheng xu de ji chu gou zao jin xing cun qu —— fa xian he jian gou 。 xie xian “/” biao shi C++ he CLI zhi jian de yi zhong bang ding (binding), you guan zhe zhong bang ding de xi jie gou cheng ben zhuan lan de chang gui zhu ti 。
  suo yi , dui yu “ shen me shi C++/CLI?” zhe ge wen ti di yi ge zui jin si de da an shi : ta shi jing tai C++ dui xiang mo xing dao dong tai CLI zu jian dui xiang mo xing de yi zhong bang ding , jian yan zhi , ta jiu shi ni ru he yong C++ jin xing .NET bian cheng , er bu shi yong C# huo Visual Basic.NET。 xiang C# he CLI zi ji yi yang ,C++/CLI zheng zai jing li ECMA( ou zhou ji suan ji zhi zao shang xie hui ) biao zhun hua bing zui zhong yao jing li ISO biao zhun ren zheng 。
  gong gong yu yan yun xing shi (CLR) shi wei ruan ban de CLI, zhuan men yong yu Windows cao zuo xi tong , tong yang ,Visual C++ 2005 shi C++/CLI de shi xian 。
  di er ge jin si da an shi : wo jiao de C++/CLI zai C++ nei ji cheng .NET bian cheng mo xing yu yi qian bei er shi yan shi zai dang shi de C++ zhong yong mo ban ji cheng fan xing bian cheng yi yang you yi qu tong gong zhi chu 。 liang zhong qing kuang zhong , ni zai xian you C++ dai ma ku shang de tou zi yi ji ni xian you de C++ zhuan ye ji shu dou de dao bao hu 。 zhe shi C++/CLI she ji de yi ge ji ben yao qiu 。
  xue xi C++/CLI
  yi zhong C++/CLI yu yan de she ji you san ge ceng mian , zhe san ge ceng mian ye shi yong yu suo you yu yan : yu yan ceng yu fa dao gong gong lei xing xi tong (CTS) de yang she ; xuan ze wei cheng xu yuan zhi jie cao zuo er gong kai de di ceng CLI ji ben zu zhi jie gou de ju ti cheng du ; yi ji xuan ze yao ti gong de chao yue CLI zhi jie zhi chi de fu jia gong neng 。
  di yi ge ceng mian shi suo you CLI yu yan zai hen da cheng du shang dou gong you de , di er ge ceng mian he di san ceng mian shi mou yi CLI yu yan qu bie yu qi ta yu yan de di fang 。 gen ju suo yao jie jue de wen ti , ni ke yi xuan ze mou yi zhong yu yan , ye ke yi jiang duo zhong CLI yu yan jie he qi lai 。 xue xi C++/CLI yu yan xu yao ba wo zhe san ge she ji ceng mian 。
  zen yang jiang C++/CLI yang she dao CTS?
  le jie di ceng CTS dui xue xi C++/CLI fei chang you bang zhu , ta zhu yao bao kuo san ge chang gui lei lei xing :
  duo tai yin yong lei xing , qi yong yu suo you de lei ji xu ;
  fei duo tai zhi lei xing , qi yong yu shi xian xu yao yun xing shi xiao lv de ju ti lei xing , ru shu zi lei xing ;
  chou xiang jie kou lei xing , qi yong yu ding yi yi ge shi xian gai jie kou de yi zu yin yong lei xing huo zhi lei xing gong tong shi yong de gong gong cao zuo ji ;
  zai she ji fang mian , sui ran CTS dao yi zu nei zhi de yu yan lei xing de yang she dui yu suo you CLI yu yan lai shuo dou shi gong tong de , dang ran , mei yi zhong CLI yu yan de yu fa ge bu xiang tong 。 li ru , zai C# zhong , wo men ke yi zhe yang lai ding yi yi ge chou xiang ji lei Shape, cong zhe ge lei pai sheng te ding de ji he mo xing dui xiang 。
  abstract class Shape { ... } // C#
  er zai C++/CLI zhong , ke yi xiang xia mian zhe yang xie , yi biao shi wan quan xiang tong de di ceng yin yong lei xing :
  ref class Shape abstract { ... }; // C++/CLI
  zai di ceng IL( zhong jian yu yan ) zhong , yi shang liang zhong sheng ming yi wan quan xiang tong de fang shi biao shi 。 tong yang , zai C# zhong , wo men ke yi yong xia mian de dai ma lai ding yi yi ge ju ti de Point2D lei :
  struct Point2D { ... } // C#
  er zai C++/CLI zhong xie cheng :
  value class Point2D { ... }; // C++/CLI
  jie zhu C++/CLI zhi chi de lei lei xing jia zu biao xian le yi zhong ben ji fang shi de CTS ji cheng 。 ta que ding le ni de yu fa xuan ze , li ru :
  class native {};
  value class V {};
  ref class R {};
  interface class I {};
  CTS ye zhi chi mei ju lei lei xing , qi xing wei fang shi yu ben ji mei ju shao wei you xie qu bie ,C++/CLI dui er zhe dou ti gong zhi chi :
  enum native { fail, pass };
  enum class CLIEnum : char { fail, pass};
  tong yang ,CTS zhi chi qi zi ji de shu zu lei xing , qi xing wei ye yu ben ji shu zu lei xing you yi ding cha bie , wei ruan tong yang dui er zhe ti gong zhi chi :
  int native[] = { 1,1,2,3,5,8 };
  array<int>^ managed = { 1,1,2,3,5,8 };
  na zhong ren wei ren he yi zhong CLI yu yan bi ling yi zhong yu yan geng jie jin huo ji hu jiu shi dao di ceng CLI de yang she shi bu jing que de 。 xiang fan , mei yi zhong CLI yu yan dou zhi shi biao da le zi ji dui di ceng CLI dui xiang mo xing de yi zhong jian jie 。 zai xia yi jie ni jiang geng qing chu di kan dao zhe yi dian 。
  zai she ji CLI yu yan shi bi xu kao lv de di er ge she ji ceng mian shi yao jiang shen me cheng du de di ceng CLI shi xian mo xing jie he dao gai yu yan zhong 。 zhe ge yu yan jie jue shen me yang de wen ti ? yao jie jue zhe xie wen ti bi xu yao shen me yang de gong ju ? ci wai , gai yu yan hen ke neng xi yin na yi lei cheng xu yuan ?
  
  
  xia mian , wo men li yong fa sheng zai tuo guan dui zhong de zhi lei xing wen ti 。 zai xu duo qing kuang xia , zhi lei xing ke yi zai tuo guan dui zhong zhao dao zi ji :
  tong guo yin shi de kuang ru / kuang chu cao zuo (boxing)—— dang zhi lei xing de mou ge shi li bei fu zhi gei yi dui xiang shi , huo zhe tong guo mou ge wei bei gai xie de zhi lei xing tiao yong yi ge xu ni fang fa shi ;
  dang zhi lei xing bei dang zuo wei yin yong lei lei xing de cheng yuan shi ;
  dang zhi lei xing bei dang zuo CLI shu zu yuan su cun chu shi ;
  shi fou da ying cheng xu yuan chu li zhe zhong zhi lei xing di zhi shi she ji CLI yu yan shi bi xu yao jie jue de wen ti 。
  cun zai de wen ti ?
  wei yu tuo guan dui zhong de ren he dui xiang zai la ji hui shou qi jin xing qing sao shou suo de guo cheng zhong dou you ke neng zao yu chong xin fen pei , zhi xiang zhe xie dui xiang de ren he zhi zhen bi xu bei zhui zong bing zai yun xing shi de dao geng xin , er cheng xu yuan wu fa zi ji shou dong zhui zong ta men , yin ci , jia ru ni bei da ying yong mou ge ke neng zai tuo guan dui zhong de zhi lei xing de di zhi , na me chu le ben ji zhi zhen wai , huan xu yao yi ge zhui zong xing tai de zhi zhen 。
  dao di gai zen yang qu quan heng ne ? yi fang mian , xu yao kao lv jian jie he an quan 。 zhi jie yin ru dui yi ge huo yi zu zhui zong zhi zhen de zhi chi hui shi yu yan bian de geng fu duo 。 jia ru bu ti gong zhe zhong zhi chi , you yu suo xu de fu duo cheng du jiang di , cong er ke yi zhao dao de cheng xu yuan ren qun jiu hui zeng jia 。 ci wai , da ying cheng xu yuan fang wen zhe xie sheng ming qi duan zan de zhi lei xing , ze zeng jia le cheng xu yuan chu cuo de ke neng xing 。 ta jing yi huo bu jing yi di dui nei cun zuo yi xie wei xian dong zuo 。 bu zhi chi zhui zong zhi zhen , ke yi qian zai di chuang jian jiao an quan de yun xing shi huan jing 。
  ling yi fang mian , bi xu kao lv xiao lv he ling huo xing 。 mei ci jiang zhi lei xing fu zhi gei xiang tong de dui xiang , gai zhi dou hui fa sheng xin de kuang ru / kuang chu cao zuo 。 da ying fang wen zhe zhong jing guo kuang ru / kuang chu cao zuo de zhi lei xing , jiu da ying zai nei cun zhong jin xing geng xin cao zuo , zhe yang bian ke neng ti gong chong yao de xing neng gai jin 。 mei you mou zhong xing shi de zhui zong zhi zhen , ni jiang wu fa yong zhi zhen suan fa bian li CLI shu zu , zhe yi wei zhe CLI shu zu jiang bu neng rong ru STL( biao zhun mo ban ku ) zhong de die dai qi mo shi , ye wu fa yu fan xing suan fa xie tong gong zuo 。 da ying fang wen kuang ru / kuang chu zhi lei xing jiang hui da da ti gao she ji de ling huo xing 。
  zai C++/CLI zhong , wei ruan xuan ze ti gong yi xi lie zai tuo guan dui zhong chu li zhi lei xing de xun zhi mo shi :
  int ival = 1024;
  int^ boxedi = ival;
  array<int>^ ia = gcnew array<int>{1,1,2,3,5,8};
  interior_ptr<int> begin = &ia[0];
  value struct smallInt { int m_ival; ... } si;
  pin_ptr<int> ppi = &si.m_ival;
  dian xing de C++/CLI kai fa ren yuan shi yi ge jing yan feng fu de xi tong cheng xu yuan , qi ren wu shi ti gong di ceng jia gou yi ji zuo wei ji chu de gai xin ying yong , yi ci wei ji chu lai gou jian wei lai 。 ta bi xu jie jue ke shen suo xing he xing neng xiang guan de wen ti , bing qie bi xu cong xi tong yi ji lai kan dai di ceng CLI。 mou zhong CLI yu yan de xi jie biao zhun fan yang le qi cheng xu yuan de mian mao 。
  fu duo xing ben shen bing bu shi dui zhi liang de fou ding , ren lei sheng ming bi dan gai xi bao fu duo de duo , zhe dang ran bu shi yi jian huai shi , ran er , dang dan yi gai nian de biao da bian de fu duo hua yi hou , zhe jing chang bei ren wei shi yi jian huai shi 。 zai C++/CLI zhong ,CLI kai fa tuan dui yi jing chang shi ti gong yi zhong you ya de fang shi lai biao da yi ge fu duo de zhu ti 。
  fu jia gong neng
  di san ge she ji ceng mian shi te ding yu yan ceng gong neng yao chao guo bei CLI zhi jie zhi chi de gong neng , zhe yang jiu xu yao jian li yi zhong yu yan ceng zhi chi yu CLI di ceng shi xian mo xing zhi jian de yang she 。 zai mou xie qing kuang xia , zhe shi zuo bu dao de , yin wei gai yu yan wu fa tiao jie CLI de xing wei , zai ji lei de gou zao han shu he xi gou han shu zhong jie jue xu han shu bian shi li zi 。 wei le zai zhe zhong qing kuang zhong fan yang ISO-C++ yu yi , xu yao zai mei ge ji lei de gou zao han shu he xi gou han shu zhong chong xin an pai xu biao 。 zhe shi bu ke neng de , yin wei xu biao cao zuo shi you yun xing shi tuo guan de , er fei dan du de yu yan tuo guan 。 yin ci , zhe yi she ji ceng mian shi you yue xing he ke xing xing de zhe zhong 。C++/CLI ti gong de fu jia gong neng zhu yao you san ge fang mian :
  yin yong lei xing de zi yuan huo qu (Resource Acquisition) xing shi shi Initialization(RAII), you qi shi wei bei cheng zuo zhan ju xi you zi yuan de la ji hui shou lei xing que ding xing zhong zhi hua (deterministic finalization) ti gong yi ge zi dong hua de ji zhi ;
  yu C++ kao bei gou zao han shu he kao bei fu zhi cao zuo fu xiang guan de shen du kao bei yu yi xing shi , dan ta bu neng kuo zhan dao zhi lei xing ;
  chu le CLI fan xing ji zhi zhi wai —— zhe yuan lai shi wo di yi ge zhuan lan de zhu ti , huan wei CTS lei xing ti gong C++ mo ban de zhi jie zhi chi , ling wai , huan ti gong yong yu CLI lei xing de STL ke yan zheng ban ben ;
  rang wo men kan yi ge jian dan de li zi : que ding xing zhong zhi hua wen ti 。 yu dui xiang guan lian de nei cun bei la ji hui shou qi hui shou zhi qian , ruo cun zai yu zhi xiang guan lian de Finalize fang fa , gai fang fa jiang hui bei tiao yong 。 ni ke yi ba gai fang fa kan zuo shi yi zhong chao ji xi gou han shu , yin wei ta bu yi kao yu gai dui xiang cheng xu de sheng ming qi , ta bei cheng wei zhong zhi hua 。 tiao yong Finalize fang fa de shi jian , shen zhi shi fou tiao yong ta shi wei ding yi de 。 zhe jiu shi la ji hui shou qi bu que ding de zhong zhi hua cao zuo han yi zhi suo zai 。
  bu que ding xing zhong zhi hua zai jin xing dong tai nei cun zhi li shi ke yi hen you xiao di gong zuo , dang ke yong nei cun kong jian yan chong bu zu shi , la ji hui shou qi hui fa hui zuo yong bing jie jue wen ti 。 dan shi dang dui xiang she ji de shi mou xie chong yao zi yuan , bi ru shu ju ku lian jie 、 mou zhong lei xing de suo 、 ben di dui nei cun shi , bu que ding xing zhong zhi hua de biao xian que bu jin ren yi 。 zai zhe zhong qing kuang xia , zui hao shi jin kuai shi fang bu zai xu yao de zi yuan 。 mu qian CLI cai yong de jie jue ban fa shi : mou ge lei zai qi IDisposable jie kou de Dispose fang fa zhong shi fang zi yuan , zhe li de wen ti shi Dispose xu yao xian shi tiao yong , yin ci ta bu ke neng bei zhi xing 。
  C++ de ji ben she ji mo shi shi qian shu de zi yuan huo qu (Resource Acquisition ) ji chu shi hua (Initialization), ta yi wei zhe lei tong guo gou zao han shu huo qu zi yuan , xiang fan , tong guo xi gou han shu lai shi fang zi yuan 。 zai lei dui xiang de sheng cun qi nei shi zi dong zhi li de 。
  yi xia shi yin yong lei xing shi fang zi yuan de guo cheng :
  yong xi gou han shu ya suo zai shi fang zi yuan guo cheng zhong bi xu de dai ma ;
  zi dong tiao yong bang ding dao lei dui xiang sheng cun qi de xi gou han shu ;
  CLI zhong , yin yong lei xing de lei mei you lei xi gou de gai nian , yin ci , xi gou han shu bei yang she dao di ceng shi xian zhong ling wai de dong xi shang , bian yi qi ze zai nei bu wan cheng ru xia zhuan huan :
  lei ju bei qi ji lei lie biao , cong jie kou IDisposable yan shen ji xu ;
  xi gou han shu bei zhuan huan cheng IDisposable de Dispose fang fa ;
  zhe jin jin wan cheng le yi ban , huan xu yao yi zhong xi gou han shu de zi dong tiao yong tu jing 。 zhi chi yin yong lei xing zhuan yong de ji yu dui zhan de fu hao , ye jiu shi shuo qi sheng ming qi yu qi sheng ming de fan wei xiang guan lian 。 bian yi qi zai nei bu zhuan huan fu hao , zai tuo guan dui zhong fen pei yin yong dui xiang 。 sui zhe fan wei de zhong zhi , bian yi qi cha ru yi ge dui Dispose fang fa de tiao yong —— yong hu ding yi de xi gou han shu 。 yu gai dui xiang guan lian de shi ji nei cun de hui shou reng ran zai la ji hui shou qi de zhang kong zhi xia 。 li ru ru Figure 1 suo shi 。
  
  
  C++/CLI bu jin jin shi C++ dao zhi li shi jie de kuo zhan , xiang fan , ta biao xian le yi zhong wan quan de bian cheng fan li , lei si yu zao qi duo chong ji xu he fan xing bian cheng fan li ji cheng dao gai yu yan yi yang , wo ren wei zhe ge tuan dui wan cheng le yi xiang jie chu de gong zuo 。
  na me , ni shi ru he kan dai C++/CLI de ne ?
  C++/CLI dai biao le ben di he tuo guan bian cheng de zong he , zai zhe ge fan fu guo cheng zhong , zhe zhong zong he tong guo ji du li er you deng tong de yuan ma ji he er jin zhi yuan su gong tong ti lai wan cheng , bao kuo hun he mo shi ( ben ji he CTS lei xing de yuan ma ji hun he , yi ji ben ji he CIL dui xiang wen jian de er jin zhi hun he ), ben di lei xing he CTS lei xing de hun he , xin zeng le hun he ben di dui xiang he CIL dui xiang de er jin zhi wen jian ), chun mo shi ( ben ji he CTS lei xing de yuan ma ji hun he , suo you bian yi guo de CIL dui xiang wen jian ), ben ji lei ( jin tong guo zhuan men de bao zhuang lei cai ke yi cao kong CTS lei xing ), yi ji CTS lei ( zhi neng yi zhi zhen xing shi cao kong ben ji lei xing )。
  dang ran ,C++/CLI cheng xu yuan ye ke yi xuan ze dan du yong CLI lei xing lai bian cheng , zai zhe zhong fang shi zhong ti gong neng bei ji su de ke yan zheng dai ma , bi ru SQL Server 2005 zhong de cun chu guo cheng 。
  xian zai , hui dao shen me shi C++/CLI de wen ti , ta shi jin ru .NET bian cheng mo xing de di yi dao men jian , you le C++/CLI, ni bu jin ju bei le qian yi C++ yuan dai ma ku de tu jing , tong shi huan ke yi qian yi C++ zhuan ye ji shu 。 zhe rang wo gan jiao fei chang shu fu 。【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
shen me shi C++/CLI?  C++/CLI miao hui de shi yi zhong duo yuan zu he , ci chu de C++ dang ran shi zhi Bjarne Stroustrup zai Bell shi yan shi fa ming de C++ bian cheng yu yan 。 ta zhi chi su du he zhi xing wen jian de da xiao dou de dao you hua de jing tai dui xiang mo xing 。 dan chu le dui nei cun fen pei yi wai , ta bu zhi chi yun xing shi cheng xu dui dui xiang de geng gai 。 ta da ying dui di ceng ji qi jin xing wu xian zhi de fang wen , dan dui yu zheng zai yun xing de cheng xu zhong de huo dong lei xing 、 yi ji xiang guan de cheng xu ji chu gou zao , ta de fang wen neng li que fei chang you xian 、 huo zhe gen ben jiu bu ke neng 。 wo zai wei ruan de tong shi Herb Sutter, ye shi C++/CLI de zhu jia gou shi , ren wei C++ shi yi ge hun ning tu yu yan 。   “CLI” ji gong gong yu yan ji chu jie gou (Common Language InfrastrUCture), zhe shi yi ge zhi chi dong tai zu jian bian cheng mo xing de duo ceng jia gou 。 zai xu duo fang mian , ta suo biao shi de dui xiang mo xing he C++ de wan quan xiang fan 。 ta shi yi ge yun xing shi ruan jian ceng , yi ge xu ni zhi xing xi tong , yun xing zai ying yong cheng xu he di ceng cao zuo xi tong zhi jian 。 dui di ceng ji qi de fang wen shou dao xiang dang yan ge de xian zhi 。 zhi chi dui yun xing zhong cheng xu de huo dong lei xing yi ji guan lian cheng xu de ji chu gou zao jin xing cun qu —— fa xian he jian gou 。 xie xian “/” biao shi C++ he CLI zhi jian de yi zhong bang ding (binding), you guan zhe zhong bang ding de xi jie gou cheng ben zhuan lan de chang gui zhu ti 。    suo yi , dui yu “ shen me shi C++/CLI?” zhe ge wen ti di yi ge zui jin si de da an shi : ta shi jing tai C++ dui xiang mo xing dao dong tai CLI zu jian dui xiang mo xing de yi zhong bang ding , jian yan zhi , ta jiu shi ni ru he yong C++ jin xing .NET bian cheng , er bu shi yong C# huo Visual Basic.NET。 xiang C# he CLI zi ji yi yang ,C++/CLI zheng zai jing li ECMA( ou zhou ji suan ji zhi zao shang xie hui ) biao zhun hua bing zui zhong yao jing li ISO biao zhun ren zheng 。    gong gong yu yan yun xing shi (CLR) shi wei ruan ban de CLI, zhuan men yong yu Windows cao zuo xi tong , tong yang ,Visual C++ 2005 shi C++/CLI de shi xian 。    di er ge jin si da an shi : wo jiao de C++/CLI zai C++ nei ji cheng .NET bian cheng mo xing yu yi qian bei er shi yan shi zai dang shi de C++ zhong yong mo ban ji cheng fan xing bian cheng yi yang you yi qu tong gong zhi chu 。 liang zhong qing kuang zhong , ni zai xian you C++ dai ma ku shang de tou zi yi ji ni xian you de C++ zhuan ye ji shu dou de dao bao hu 。 zhe shi C++/CLI she ji de yi ge ji ben yao qiu 。    xue xi C++/CLI    yi zhong C++/CLI yu yan de she ji you san ge ceng mian , zhe san ge ceng mian ye shi yong yu suo you yu yan : yu yan ceng yu fa dao gong gong lei xing xi tong (CTS) de yang she ; xuan ze wei cheng xu yuan zhi jie cao zuo er gong kai de di ceng CLI ji ben zu zhi jie gou de ju ti cheng du ; yi ji xuan ze yao ti gong de chao yue CLI zhi jie zhi chi de fu jia gong neng 。    di yi ge ceng mian shi suo you CLI yu yan zai hen da cheng du shang dou gong you de , di er ge ceng mian he di san ceng mian shi mou yi CLI yu yan qu bie yu qi ta yu yan de di fang 。 gen ju suo yao jie jue de wen ti , ni ke yi xuan ze mou yi zhong yu yan , ye ke yi jiang duo zhong CLI yu yan jie he qi lai 。 xue xi C++/CLI yu yan xu yao ba wo zhe san ge she ji ceng mian 。    zen yang jiang C++/CLI yang she dao CTS?    le jie di ceng CTS dui xue xi C++/CLI fei chang you bang zhu , ta zhu yao bao kuo san ge chang gui lei lei xing :    duo tai yin yong lei xing , qi yong yu suo you de lei ji xu ;    fei duo tai zhi lei xing , qi yong yu shi xian xu yao yun xing shi xiao lv de ju ti lei xing , ru shu zi lei xing ;    chou xiang jie kou lei xing , qi yong yu ding yi yi ge shi xian gai jie kou de yi zu yin yong lei xing huo zhi lei xing gong tong shi yong de gong gong cao zuo ji ;    zai she ji fang mian , sui ran CTS dao yi zu nei zhi de yu yan lei xing de yang she dui yu suo you CLI yu yan lai shuo dou shi gong tong de , dang ran , mei yi zhong CLI yu yan de yu fa ge bu xiang tong 。 li ru , zai C# zhong , wo men ke yi zhe yang lai ding yi yi ge chou xiang ji lei Shape, cong zhe ge lei pai sheng te ding de ji he mo xing dui xiang 。      abstract class Shape { ... } // C#    er zai C++/CLI zhong , ke yi xiang xia mian zhe yang xie , yi biao shi wan quan xiang tong de di ceng yin yong lei xing :      ref class Shape abstract { ... }; // C++/CLI    zai di ceng IL( zhong jian yu yan ) zhong , yi shang liang zhong sheng ming yi wan quan xiang tong de fang shi biao shi 。 tong yang , zai C# zhong , wo men ke yi yong xia mian de dai ma lai ding yi yi ge ju ti de Point2D lei :      struct Point2D { ... } // C#    er zai C++/CLI zhong xie cheng :      value class Point2D { ... }; // C++/CLI    jie zhu C++/CLI zhi chi de lei lei xing jia zu biao xian le yi zhong ben ji fang shi de CTS ji cheng 。 ta que ding le ni de yu fa xuan ze , li ru :      class native {};   value class V {};   ref class R {};   interface class I {};   CTS ye zhi chi mei ju lei lei xing , qi xing wei fang shi yu ben ji mei ju shao wei you xie qu bie ,C++/CLI dui er zhe dou ti gong zhi chi :      enum native { fail, pass };   enum class CLIEnum : char { fail, pass};    tong yang ,CTS zhi chi qi zi ji de shu zu lei xing , qi xing wei ye yu ben ji shu zu lei xing you yi ding cha bie , wei ruan tong yang dui er zhe ti gong zhi chi :      int native[] = { 1,1,2,3,5,8 };   array<int>^ managed = { 1,1,2,3,5,8 };    na zhong ren wei ren he yi zhong CLI yu yan bi ling yi zhong yu yan geng jie jin huo ji hu jiu shi dao di ceng CLI de yang she shi bu jing que de 。 xiang fan , mei yi zhong CLI yu yan dou zhi shi biao da le zi ji dui di ceng CLI dui xiang mo xing de yi zhong jian jie 。 zai xia yi jie ni jiang geng qing chu di kan dao zhe yi dian 。    zai she ji CLI yu yan shi bi xu kao lv de di er ge she ji ceng mian shi yao jiang shen me cheng du de di ceng CLI shi xian mo xing jie he dao gai yu yan zhong 。 zhe ge yu yan jie jue shen me yang de wen ti ? yao jie jue zhe xie wen ti bi xu yao shen me yang de gong ju ? ci wai , gai yu yan hen ke neng xi yin na yi lei cheng xu yuan ? xia mian , wo men li yong fa sheng zai tuo guan dui zhong de zhi lei xing wen ti 。 zai xu duo qing kuang xia , zhi lei xing ke yi zai tuo guan dui zhong zhao dao zi ji :    tong guo yin shi de kuang ru / kuang chu cao zuo (boxing)—— dang zhi lei xing de mou ge shi li bei fu zhi gei yi dui xiang shi , huo zhe tong guo mou ge wei bei gai xie de zhi lei xing tiao yong yi ge xu ni fang fa shi ;    dang zhi lei xing bei dang zuo wei yin yong lei lei xing de cheng yuan shi ;    dang zhi lei xing bei dang zuo CLI shu zu yuan su cun chu shi ;    shi fou da ying cheng xu yuan chu li zhe zhong zhi lei xing di zhi shi she ji CLI yu yan shi bi xu yao jie jue de wen ti 。    cun zai de wen ti ?    wei yu tuo guan dui zhong de ren he dui xiang zai la ji hui shou qi jin xing qing sao shou suo de guo cheng zhong dou you ke neng zao yu chong xin fen pei , zhi xiang zhe xie dui xiang de ren he zhi zhen bi xu bei zhui zong bing zai yun xing shi de dao geng xin , er cheng xu yuan wu fa zi ji shou dong zhui zong ta men , yin ci , jia ru ni bei da ying yong mou ge ke neng zai tuo guan dui zhong de zhi lei xing de di zhi , na me chu le ben ji zhi zhen wai , huan xu yao yi ge zhui zong xing tai de zhi zhen 。    dao di gai zen yang qu quan heng ne ? yi fang mian , xu yao kao lv jian jie he an quan 。 zhi jie yin ru dui yi ge huo yi zu zhui zong zhi zhen de zhi chi hui shi yu yan bian de geng fu duo 。 jia ru bu ti gong zhe zhong zhi chi , you yu suo xu de fu duo cheng du jiang di , cong er ke yi zhao dao de cheng xu yuan ren qun jiu hui zeng jia 。 ci wai , da ying cheng xu yuan fang wen zhe xie sheng ming qi duan zan de zhi lei xing , ze zeng jia le cheng xu yuan chu cuo de ke neng xing 。 ta jing yi huo bu jing yi di dui nei cun zuo yi xie wei xian dong zuo 。 bu zhi chi zhui zong zhi zhen , ke yi qian zai di chuang jian jiao an quan de yun xing shi huan jing 。    ling yi fang mian , bi xu kao lv xiao lv he ling huo xing 。 mei ci jiang zhi lei xing fu zhi gei xiang tong de dui xiang , gai zhi dou hui fa sheng xin de kuang ru / kuang chu cao zuo 。 da ying fang wen zhe zhong jing guo kuang ru / kuang chu cao zuo de zhi lei xing , jiu da ying zai nei cun zhong jin xing geng xin cao zuo , zhe yang bian ke neng ti gong chong yao de xing neng gai jin 。 mei you mou zhong xing shi de zhui zong zhi zhen , ni jiang wu fa yong zhi zhen suan fa bian li CLI shu zu , zhe yi wei zhe CLI shu zu jiang bu neng rong ru STL( biao zhun mo ban ku ) zhong de die dai qi mo shi , ye wu fa yu fan xing suan fa xie tong gong zuo 。 da ying fang wen kuang ru / kuang chu zhi lei xing jiang hui da da ti gao she ji de ling huo xing 。    zai C++/CLI zhong , wei ruan xuan ze ti gong yi xi lie zai tuo guan dui zhong chu li zhi lei xing de xun zhi mo shi :      int ival = 1024;   int^ boxedi = ival;      array<int>^ ia = gcnew array<int>{1,1,2,3,5,8};   interior_ptr<int> begin = &ia[0];      value struct smallInt { int m_ival; ... } si;   pin_ptr<int> ppi = &si.m_ival;    dian xing de C++/CLI kai fa ren yuan shi yi ge jing yan feng fu de xi tong cheng xu yuan , qi ren wu shi ti gong di ceng jia gou yi ji zuo wei ji chu de gai xin ying yong , yi ci wei ji chu lai gou jian wei lai 。 ta bi xu jie jue ke shen suo xing he xing neng xiang guan de wen ti , bing qie bi xu cong xi tong yi ji lai kan dai di ceng CLI。 mou zhong CLI yu yan de xi jie biao zhun fan yang le qi cheng xu yuan de mian mao 。    fu duo xing ben shen bing bu shi dui zhi liang de fou ding , ren lei sheng ming bi dan gai xi bao fu duo de duo , zhe dang ran bu shi yi jian huai shi , ran er , dang dan yi gai nian de biao da bian de fu duo hua yi hou , zhe jing chang bei ren wei shi yi jian huai shi 。 zai C++/CLI zhong ,CLI kai fa tuan dui yi jing chang shi ti gong yi zhong you ya de fang shi lai biao da yi ge fu duo de zhu ti 。    fu jia gong neng    di san ge she ji ceng mian shi te ding yu yan ceng gong neng yao chao guo bei CLI zhi jie zhi chi de gong neng , zhe yang jiu xu yao jian li yi zhong yu yan ceng zhi chi yu CLI di ceng shi xian mo xing zhi jian de yang she 。 zai mou xie qing kuang xia , zhe shi zuo bu dao de , yin wei gai yu yan wu fa tiao jie CLI de xing wei , zai ji lei de gou zao han shu he xi gou han shu zhong jie jue xu han shu bian shi li zi 。 wei le zai zhe zhong qing kuang zhong fan yang ISO-C++ yu yi , xu yao zai mei ge ji lei de gou zao han shu he xi gou han shu zhong chong xin an pai xu biao 。 zhe shi bu ke neng de , yin wei xu biao cao zuo shi you yun xing shi tuo guan de , er fei dan du de yu yan tuo guan 。 yin ci , zhe yi she ji ceng mian shi you yue xing he ke xing xing de zhe zhong 。C++/CLI ti gong de fu jia gong neng zhu yao you san ge fang mian :    yin yong lei xing de zi yuan huo qu (Resource Acquisition) xing shi shi Initialization(RAII), you qi shi wei bei cheng zuo zhan ju xi you zi yuan de la ji hui shou lei xing que ding xing zhong zhi hua (deterministic finalization) ti gong yi ge zi dong hua de ji zhi ;    yu C++ kao bei gou zao han shu he kao bei fu zhi cao zuo fu xiang guan de shen du kao bei yu yi xing shi , dan ta bu neng kuo zhan dao zhi lei xing ;    chu le CLI fan xing ji zhi zhi wai —— zhe yuan lai shi wo di yi ge zhuan lan de zhu ti , huan wei CTS lei xing ti gong C++ mo ban de zhi jie zhi chi , ling wai , huan ti gong yong yu CLI lei xing de STL ke yan zheng ban ben ;    rang wo men kan yi ge jian dan de li zi : que ding xing zhong zhi hua wen ti 。 yu dui xiang guan lian de nei cun bei la ji hui shou qi hui shou zhi qian , ruo cun zai yu zhi xiang guan lian de Finalize fang fa , gai fang fa jiang hui bei tiao yong 。 ni ke yi ba gai fang fa kan zuo shi yi zhong chao ji xi gou han shu , yin wei ta bu yi kao yu gai dui xiang cheng xu de sheng ming qi , ta bei cheng wei zhong zhi hua 。 tiao yong Finalize fang fa de shi jian , shen zhi shi fou tiao yong ta shi wei ding yi de 。 zhe jiu shi la ji hui shou qi bu que ding de zhong zhi hua cao zuo han yi zhi suo zai 。    bu que ding xing zhong zhi hua zai jin xing dong tai nei cun zhi li shi ke yi hen you xiao di gong zuo , dang ke yong nei cun kong jian yan chong bu zu shi , la ji hui shou qi hui fa hui zuo yong bing jie jue wen ti 。 dan shi dang dui xiang she ji de shi mou xie chong yao zi yuan , bi ru shu ju ku lian jie 、 mou zhong lei xing de suo 、 ben di dui nei cun shi , bu que ding xing zhong zhi hua de biao xian que bu jin ren yi 。 zai zhe zhong qing kuang xia , zui hao shi jin kuai shi fang bu zai xu yao de zi yuan 。 mu qian CLI cai yong de jie jue ban fa shi : mou ge lei zai qi IDisposable jie kou de Dispose fang fa zhong shi fang zi yuan , zhe li de wen ti shi Dispose xu yao xian shi tiao yong , yin ci ta bu ke neng bei zhi xing 。   C++ de ji ben she ji mo shi shi qian shu de zi yuan huo qu (Resource Acquisition ) ji chu shi hua (Initialization), ta yi wei zhe lei tong guo gou zao han shu huo qu zi yuan , xiang fan , tong guo xi gou han shu lai shi fang zi yuan 。 zai lei dui xiang de sheng cun qi nei shi zi dong zhi li de 。    yi xia shi yin yong lei xing shi fang zi yuan de guo cheng :    yong xi gou han shu ya suo zai shi fang zi yuan guo cheng zhong bi xu de dai ma ;    zi dong tiao yong bang ding dao lei dui xiang sheng cun qi de xi gou han shu ;   CLI zhong , yin yong lei xing de lei mei you lei xi gou de gai nian , yin ci , xi gou han shu bei yang she dao di ceng shi xian zhong ling wai de dong xi shang , bian yi qi ze zai nei bu wan cheng ru xia zhuan huan :    lei ju bei qi ji lei lie biao , cong jie kou IDisposable yan shen ji xu ;    xi gou han shu bei zhuan huan cheng IDisposable de Dispose fang fa ;    zhe jin jin wan cheng le yi ban , huan xu yao yi zhong xi gou han shu de zi dong tiao yong tu jing 。 zhi chi yin yong lei xing zhuan yong de ji yu dui zhan de fu hao , ye jiu shi shuo qi sheng ming qi yu qi sheng ming de fan wei xiang guan lian 。 bian yi qi zai nei bu zhuan huan fu hao , zai tuo guan dui zhong fen pei yin yong dui xiang 。 sui zhe fan wei de zhong zhi , bian yi qi cha ru yi ge dui Dispose fang fa de tiao yong —— yong hu ding yi de xi gou han shu 。 yu gai dui xiang guan lian de shi ji nei cun de hui shou reng ran zai la ji hui shou qi de zhang kong zhi xia 。 li ru ru Figure 1 suo shi 。   C++/CLI bu jin jin shi C++ dao zhi li shi jie de kuo zhan , xiang fan , ta biao xian le yi zhong wan quan de bian cheng fan li , lei si yu zao qi duo chong ji xu he fan xing bian cheng fan li ji cheng dao gai yu yan yi yang , wo ren wei zhe ge tuan dui wan cheng le yi xiang jie chu de gong zuo 。    na me , ni shi ru he kan dai C++/CLI de ne ?   C++/CLI dai biao le ben di he tuo guan bian cheng de zong he , zai zhe ge fan fu guo cheng zhong , zhe zhong zong he tong guo ji du li er you deng tong de yuan ma ji he er jin zhi yuan su gong tong ti lai wan cheng , bao kuo hun he mo shi ( ben ji he CTS lei xing de yuan ma ji hun he , yi ji ben ji he CIL dui xiang wen jian de er jin zhi hun he ), ben di lei xing he CTS lei xing de hun he , xin zeng le hun he ben di dui xiang he CIL dui xiang de er jin zhi wen jian ), chun mo shi ( ben ji he CTS lei xing de yuan ma ji hun he , suo you bian yi guo de CIL dui xiang wen jian ), ben ji lei ( jin tong guo zhuan men de bao zhuang lei cai ke yi cao kong CTS lei xing ), yi ji CTS lei ( zhi neng yi zhi zhen xing shi cao kong ben ji lei xing )。    dang ran ,C++/CLI cheng xu yuan ye ke yi xuan ze dan du yong CLI lei xing lai bian cheng , zai zhe zhong fang shi zhong ti gong neng bei ji su de ke yan zheng dai ma , bi ru SQL Server 2005 zhong de cun chu guo cheng 。    xian zai , hui dao shen me shi C++/CLI de wen ti , ta shi jin ru .NET bian cheng mo xing de di yi dao men jian , you le C++/CLI, ni bu jin ju bei le qian yi C++ yuan dai ma ku de tu jing , tong shi huan ke yi qian yi C++ zhuan ye ji shu 。 zhe rang wo gan jiao fei chang shu fu 。
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
桌球宝贝_性感在蔓延(3)
桌球宝贝_性感在蔓延(2)
银杏树下清纯女孩(9)
银杏树下清纯女孩(8)
痞子的甘南日记
疑是银河落九天
雪域坝上四——纯美色
冬日恋歌——西城杨柳弄轻柔
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有