| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c/c++ >> C++ yun suan fu chong zai zhuan huan yun suan fu

C++ yun suan fu chong zai zhuan huan yun suan fu

2008-06-01 02:07:18 编辑來源:互联网 评论
 
 
 
本文为【C++运算符重载转换运算符】的拼音翻译版
  wei shen me xu yao zhuan huan yun suan fu ? da jia zhi dao dui yu nei zhi lei xing de shu ju wo men ke yi tong guo qiang zhi zhuan huan fu de shi yong lai zhuan huan shu ju , li ru (int)2.1f; zi ding yi lei ye shi lei xing , na me zi ding yi lei de dui xiang zai hen duo qing kuang xia ye xu yao zhi chi ci cao zuo ,C++ ti gong le zhuan huan yun suan fu chong zai han shu , ta shi de zi ding yi lei dui xiang de qiang zhuan huan cheng wei ke neng 。
  zhuan huan yun suan fu de sheng ming fang shi bi jiao fei fan , fang fa ru xia :
  Operator lei ming ();
  zhuan huan yun suan fu de chong zai han shu shi mei you fan hui lei xing de , ta he lei de gou zao han shu , xi gou han shu yi yang shi bu zun xun han shu you fan hui lei xing de gui ding de , ta men dou mei you fan hui zhi 。
  xia mian wo kan yi ge li zi , kan kan ta shi ru he gong zuo de :
  // li 1
  // cheng xu zuo zhe : guan ning
  // zhan dian :www.cndev-lab.com
  // suo you gao jian yun you ban quan , ru yao zhuan zai , qing wu bi wen ming chu chu he zuo zhe
  
  #include <iostream>
  using namespace std;
  
  class Test
  {
   public:
   Test(int a = 0)
   {
   cout<<this<<":"<<" zai ru gou zao han shu !"<<a<<endl;
   Test::a = a;
   }
   Test(Test &temp)
   {
   cout<<" zai ru kao bei gou zao han shu !"<<endl;
   Test::a = temp.a;
   }
   ~Test()
   {
   cout<<this<<":"<<" zai ru xi gou han shu !"<<this->a<<endl;
   cin.get();
   }
   operator int()// zhuan huan yun suan fu
   {
   cout<<this<<":"<<" zai ru zhuan huan yun suan fu han shu !"<<this->a<<endl;
   return Test::a;
   }
   public:
   int a;
  };
  int main()
  {
   Test b(99);
   cout<<"b de nei cun di zhi "<<&b<<endl;
   cout<<(int)b<<endl;// qiang zhuan huan
  
   system("pause");
  }
  zai li zi zhong wo men li yong zhuan huan yun suan fu jiang Test lei de dui xiang qiang zhuan huan cheng le int lei xing bing shu chu , zhu chong guan cha zhuan huan yun suan fu han shu de yun xing zhuang tai , fa xian bing mei you chan sheng lin shi dui xiang , zheng shi le ta yu pu tong han shu bing bu xiang tong , sui ran ta dai you return yu ju 。
  zai hen duo qing kuang xia , lei de qiang zhuan huan yun suan fu huan ke yi zuo wei lei dui xiang jia yun suan chong zai han shu shi yong , jin guan ta men de yi yi bing bu xiang tong , xia mian de li zi , jiu shi li yong zhuan huan yun suan fu , jiang liang ge lei dui xiang zhuan huan cheng int hou , xiang jia bing chuang jian lin shi lei dui xiang , hou zai fu gei ling yi ge dui xiang 。
  dai ma ru xia :// li 2
  // cheng xu zuo zhe : guan ning
  // zhan dian :www.cndev-lab.com
  // suo you gao jian yun you ban quan , ru yao zhuan zai , qing wu bi wen ming chu chu he zuo zhe
  
  #include <iostream>
  using namespace std;
  
  class Test
  {
   public:
   Test(int a = 0)
   {
   cout<<this<<":"<<" zai ru gou zao han shu !"<<a<<endl;
   Test::a = a;
   }
   Test(Test &temp)
   {
   cout<<" zai ru kao bei gou zao han shu !"<<endl;
   Test::a = temp.a;
   }
   ~Test()
   {
   cout<<this<<":"<<" zai ru xi gou han shu !"<<this->a<<endl;
   cin.get();
   }
   operator int()
   {
   cout<<this<<":"<<" zai ru zhuan huan yun suan fu han shu de nei cun di zhi :"<<this->a<<endl;
   return Test::a;
   }
   public:
   int a;
  };
  int main()
  {
   Test a(100),b(100),c;
   cout<<"a de nei cun di zhi "<<&a<<" b de nei cun di zhi "<<&b<<endl;
   c=Test((int)a+(int)b);// xian shi shi zhuan huan
  
   //c=a+b;// yin shi zhuan huan
   cout<<"c de nei cun di zhi "<<&c<<endl;
   cout<<c.a<<endl;
   system("pause");
  }
  dai ma zhong de c=a+b; shu yu yin shi zhuan huan , ta de shi xian guo cheng yu c=Test((int)a+(int)b); wan quan xiang tong 。
  yun xing jie guo ru xia tu shi ( zhu chong guan cha nei cun di zhi , guan cha gou zao yu xi gou guo cheng , zhi xing guo cheng tu zhong you jie shi ):
C++运算符重载转换运算符

  dang yi ge lei han you zhuan huan yun suan fu chong zai han shu de shi hou , you shi hou hui po huai C++ yuan you gui ze , dao zhi yun suan xiao lv jiang di , zhe yi dian bu de bu zhu chong 。
  shi li ru xia :
  // li 3
  // cheng xu zuo zhe : guan ning
  // zhan dian :www.cndev-lab.com
  // suo you gao jian yun you ban quan , ru yao zhuan zai , qing wu bi wen ming chu chu he zuo zhe
  
  #include <iostream>
  using namespace std;
  
  class Test
  {
   public:
   Test(int a = 0)
   {
   cout<<this<<":"<<" zai ru gou zao han shu !"<<a<<endl;
   Test::a = a;
   }
   Test(Test &temp)
   {
   cout<<" zai ru kao bei gou zao han shu !"<<endl;
   Test::a = temp.a;
   }
   ~Test()
   {
   cout<<this<<":"<<" zai ru xi gou han shu !"<<this->a<<endl;
   cin.get();
   }
   operator int()// zhuan huan yun suan fu , qu diao ze bu hui tiao yong
   {
   cout<<this<<":"<<" zai ru zhuan huan yun suan fu han shu de nei cun di zhi :"<<this->a<<endl;
   return Test::a;
   }
   public:
   int a;
  };
  int main()
  
   {
   Test b=Test(99);// zhu chong zhe li
   cout<<"b de nei cun di zhi "<<&b<<endl;
   cout<<b.a<<endl;
   system("pause");
  }
  an zhao C++ dui wu ming dui xiang de yue ding ,Test b=Test(99);C++ shi hui an zhao Test b(99); lai chu li de , ke shi you yu zhuan huan yun suan fu de jia ru , dao zhi zhe yi gui lv bei po huai , xi tong hui “ cuo wu de ” ren wei ni shi yao gei dui xiang fu zhi , suo yi xi tong shou xian li yong Test(99) chuang jian yi ge lin shi dui xiang yong yu fu zhi guo cheng shi yong , ke shi qia qia xi tong you mei you shi yong zi dong ti gong de fu zhi yun suan chong zai han shu qu chu li , yin wei fa xian b dui xiang bing wei gou zao , zhuan er you bu de bu jiang kai shi yuan ben yong yu fu zhi er chuang jian de lin shi dui xiang zai ci de qiang zhuan huan wei int lei xing , ti gong gei b dui xiang jin xing gou zao , ke jian zhong jian de chuang jian lin shi dui xiang he zai ru zhuan huan yun suan fu han shu de guo cheng wan quan shi duo yu , du zhe dui ci li yao ren zhen jie du , chong fen li jie 。
  yun xing jie guo ru xia tu suo shi ( yun xing guo cheng de jie shi jian tu ):
C++运算符重载转换运算符

  you yu lei de zhuan huan yun suan fu yu lei de yun suan fu chong zai han shu , zai mou xie di fang shang shi yong de shi hou , you gong neng xiang si de di fang , jia ru liang zhe dou cun zai yu lei zhong , na me sui ran yun xing jie guo zheng que , dan qi yun xing guo cheng hui chu xian yi xie yi xiang bu dao de bu zhou , dao zhi cheng xu yun xing xiao lv jiang di 。
  xia mian de li zi jiu shi zhe ge qing kuang , dai ma ru xia :// li 4
  // cheng xu zuo zhe : guan ning
  // zhan dian :www.cndev-lab.com
  // suo you gao jian yun you ban quan , ru yao zhuan zai , qing wu bi wen ming chu chu he zuo zhe
  
  #include <iostream>
  using namespace std;
  
  class Test
  {
   public:
   Test(int a = 0)
   {
   cout<<this<<":"<<" zai ru gou zao han shu !"<<a<<endl;
   Test::a = a;
   }
   Test(Test &temp)
   {
   cout<<" zai ru kao bei gou zao han shu !"<<endl;
   Test::a = temp.a;
   }
   ~Test()
   {
   cout<<this<<":"<<" zai ru xi gou han shu !"<<this->a<<endl;
   cin.get();
   }
   Test operator +(Test& temp2)
   {
   cout<<this<<""<<&temp2<<" zai ru jia yun suan fu chong zai han shu !"<<endl;
  
   Test result(this->a+temp2.a);
   return result;
   }
   operator int()
   {
   cout<<this<<":"<<" zai ru zhuan huan yun suan fu han shu de nei cun di zhi :"<<this->a<<endl;
   return Test::a;
   }
   public:
   int a;
  };
  int main()
  {
   Test a(100),b(100);
   cout<<"a de nei cun di zhi :"<<&a<<" b de nei cun di zhi :"<<&b<<endl;
   Test c=a+b;
   cout<<"c de nei cun di zhi :"<<&c<<endl;
   cout<<c.a<<endl;
   system("pause");
  }
  yun xing guo cheng jian xia tu 。
C++运算符重载转换运算符

  cong tu zhong wo men ke yi qing chu de kan dao , bu bi yao de yun suan guo cheng bei zhi xing , dao zhi kai xiao zeng da , du zhe zai li jie ci li de shi hou yao ge wai xiao xin !
  xian zai zong jie yi xia zhuan huan yun suan fu de you dian yu que dian :
  you dian : zai bu ti gong dai you lei dui xiang shen shu de yun suan fu chong zai han shu de qing kuang xia , zhuan huan yun suan fu chong zai han shu ke yi jiang lei dui xiang zhuan huan cheng xu yao de lei xing , ran hou jin xing yun suan , zui hou zai gou zao cheng lei dui xiang , zhe yi dian he lei de yun suan fu chong zai han shu you xiang tong de gong xiao 。( li 2 jiu shi zhe zhong qing kuang )
  que dian : jia ru yi ge lei zhi you zhuan huan yun suan fu chong zai han shu , er mei you zhen zheng yi yi shang yun suan fu chong zai han shu , dang yong zhuan huan yun suan fu chong zai han shu ti dai yun suan fu chong zai han shu , jin xing gong zuo de shi hou , jiu hui rang cheng xu de ke du xing jiang di , wai qu le yun suan fu cao zuo de zhen zheng han yi 。( li 2 zhong de c=a+b;// yin shi zhuan huan , jiu shi li zi , shi shi shang a+b de zuo yong zhi shi dui fan hui de zheng xing shu ju jin xing le jia yun suan , er dui xiang fu zhi de cao zuo shi xi tong yin shi de bang da jia zhuan huan cheng le c=Test(a+b)。)
  zui hou wo men lai shuo yi xia , duo lu jing zhuan huan de duo yi xing wen ti , duo yi xing wen ti yi zhi shi C++ bian cheng zhong qing yi hu shi de wen ti , dan ta de que shi bu rong xiao shi , dang wen ti yin cang qi lai de shi hou ni bu hui fa jiao , yi dan chu fa ma fan jiu lai le 。
  lei de zhuan huan gou zao han shu yu lei de zhuan huan yun suan fu chong zai han shu shi hu ni de 。( li 3 zhong de Test(int a = 0) shi jiang int lei xing de shu ju zhuan huan gou zao cheng Test lei dui xiang , er operator int() ze shi jiang Test lei dui xiang zhuan huan cheng int lei xing shu ju )
  dan shi dang ta men shi chu xian zai liang ge bu tong de lei zhong , dui yu yi ge lei dui xiang zhuan huan lai shuo , tong shi yong you liang zhong jin si de zhuan huan tu jing de shi hou , duo yi xing de wen ti jiu bao lu chu lai , dao zhi bian yi chu cuo 。
  xia li jiu shi zhe ge zhuang tai :
  // cheng xu zuo zhe : guan ning
  // zhan dian :www.cndev-lab.com
  // suo you gao jian yun you ban quan , ru yao zhuan zai , qing wu bi wen ming chu chu he zuo zhe
  #include <iostream>
  using namespace std;
  class B;
  class A
  {
   public:
   A(B &);// zhuan huan gou zao han shu , ta de zuo yong shi yong B lei dui xiang gou zao A lei dui xiang
   void Edita(int temp)
   {
   A::a=temp;
   }
  
   public:
   int a;
  };
  class B
  {
   public:
   B(int a=0)
   {
   B::a=a;
   }
   int Ra()
   {
   return B::a;
   }
   operator A()// zhuan huan yun suan fu chong zai han shu , ta de zuo yong ze shi jiang B lei dui xiang zhuan huan cheng A lei dui xiang
   {
   return *this;
   }
   PRotected:
   int a;
  };
  A::A(B &temp)
  {
   cout<<this<<""<<&temp<<endl;
   A::a=temp.Ra();
  }
  void tp(A temp)
  {
  
  }
  int main()
  {
   B BT(100);
   A at=A(bt);
   //tp(bt);// cuo wu , duo yi xing wen ti , xi tong bu zhi dao ru he xuan ze , shi xuan ze A(B &) zhuan hua gou zao hao ne ? huan shi xuan ze B::operator A() jin xing zhuan huan hao ne ?
   tp(A::A(bt));// xian shi de chu li ke yi xiao chu duo yi xing wen ti
   system("pause");
  }
  dai ma zhong de A at=A(bt); yun xing zheng chang , yin wei xi tong fa xian dui xiang at huan wei gou zao , suo yi you xian xuan qu le A lei de zhuan huan gou zao han shu chu li le , mei you chan sheng er yi xing wen ti 。
  dan shi dai ma zhong de tp(bt); bian yi cuo wu , zhe shi yin wei han shu tp de shen shu yao qiu de shi yi ge A lei dui xiang , er wo men gei ta de ze shi yi ge B lei dui xiang , er zai A lei yu B lei zhong dou you yi ge lei si de cao zuo , ke yi jiang B lei dui xiang zhuan huan cheng A lei dui xiang , xi tong bu zhi dao shi xuan qu A lei de zhuan huan gou zao han shu jin xing gou zao chu li , huan shi xuan ze B lei zhong de zhuan huan yun suan fu hao chong zai han shu chu li , xi tong ju jue cong ta men liang ge zhong xuan yi ge , suo yi bian yi cuo wu 。
  wo men xiu gai tp(bt) wei tp(A::A(bt)); bian yi zheng chang , yin wei wo men xian shi de ming que de gao su xi tong ying gai shi yong A lei de zhuan huan gou zao han shu chu li , suo yi , xian shi de gao su ji suan ji ying gai ru he chu li shu ju , tong chang ke yi jie jue duo yi xing wen ti 。【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

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

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

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

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

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

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

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

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

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

 
 
   wei shen me xu yao zhuan huan yun suan fu ?   da jia zhi dao dui yu nei zhi lei xing de shu ju wo men ke yi tong guo qiang zhi zhuan huan fu de shi yong lai zhuan huan shu ju , li ru (int)2.1f; zi ding yi lei ye shi lei xing , na me zi ding yi lei de dui xiang zai hen duo qing kuang xia ye xu yao zhi chi ci cao zuo ,C++ ti gong le zhuan huan yun suan fu chong zai han shu , ta shi de zi ding yi lei dui xiang de qiang zhuan huan cheng wei ke neng 。   zhuan huan yun suan fu de sheng ming fang shi bi jiao fei fan , fang fa ru xia :    Operator lei ming ();    zhuan huan yun suan fu de chong zai han shu shi mei you fan hui lei xing de , ta he lei de gou zao han shu , xi gou han shu yi yang shi bu zun xun han shu you fan hui lei xing de gui ding de , ta men dou mei you fan hui zhi 。    xia mian wo kan yi ge li zi , kan kan ta shi ru he gong zuo de : // li 1 // cheng xu zuo zhe : guan ning // zhan dian :www.cndev-lab.com // suo you gao jian yun you ban quan , ru yao zhuan zai , qing wu bi wen ming chu chu he zuo zhe #include <iostream> using namespace std; class Test { public: Test(int a = 0) { cout<<this<<":"<<" zai ru gou zao han shu !"<<a<<endl; Test::a = a; } Test(Test &temp) { cout<<" zai ru kao bei gou zao han shu !"<<endl; Test::a = temp.a; } ~Test() { cout<<this<<":"<<" zai ru xi gou han shu !"<<this->a<<endl; cin.get(); } operator int()// zhuan huan yun suan fu { cout<<this<<":"<<" zai ru zhuan huan yun suan fu han shu !"<<this->a<<endl; return Test::a; } public: int a; }; int main() { Test b(99); cout<<"b de nei cun di zhi "<<&b<<endl; cout<<(int)b<<endl;// qiang zhuan huan system("pause"); }    zai li zi zhong wo men li yong zhuan huan yun suan fu jiang Test lei de dui xiang qiang zhuan huan cheng le int lei xing bing shu chu , zhu chong guan cha zhuan huan yun suan fu han shu de yun xing zhuang tai , fa xian bing mei you chan sheng lin shi dui xiang , zheng shi le ta yu pu tong han shu bing bu xiang tong , sui ran ta dai you return yu ju 。    zai hen duo qing kuang xia , lei de qiang zhuan huan yun suan fu huan ke yi zuo wei lei dui xiang jia yun suan chong zai han shu shi yong , jin guan ta men de yi yi bing bu xiang tong , xia mian de li zi , jiu shi li yong zhuan huan yun suan fu , jiang liang ge lei dui xiang zhuan huan cheng int hou , xiang jia bing chuang jian lin shi lei dui xiang , hou zai fu gei ling yi ge dui xiang 。    dai ma ru xia :// li 2 // cheng xu zuo zhe : guan ning // zhan dian :www.cndev-lab.com // suo you gao jian yun you ban quan , ru yao zhuan zai , qing wu bi wen ming chu chu he zuo zhe #include <iostream> using namespace std; class Test { public: Test(int a = 0) { cout<<this<<":"<<" zai ru gou zao han shu !"<<a<<endl; Test::a = a; } Test(Test &temp) { cout<<" zai ru kao bei gou zao han shu !"<<endl; Test::a = temp.a; } ~Test() { cout<<this<<":"<<" zai ru xi gou han shu !"<<this->a<<endl; cin.get(); } operator int() { cout<<this<<":"<<" zai ru zhuan huan yun suan fu han shu de nei cun di zhi :"<<this->a<<endl; return Test::a; } public: int a; }; int main() { Test a(100),b(100),c; cout<<"a de nei cun di zhi "<<&a<<" b de nei cun di zhi "<<&b<<endl; c=Test((int)a+(int)b);// xian shi shi zhuan huan //c=a+b;// yin shi zhuan huan cout<<"c de nei cun di zhi "<<&c<<endl; cout<<c.a<<endl; system("pause"); }    dai ma zhong de c=a+b; shu yu yin shi zhuan huan , ta de shi xian guo cheng yu c=Test((int)a+(int)b); wan quan xiang tong 。    yun xing jie guo ru xia tu shi ( zhu chong guan cha nei cun di zhi , guan cha gou zao yu xi gou guo cheng , zhi xing guo cheng tu zhong you jie shi ): [url=http://www.wangchao.net.cn/bbs/pydetail_1785399.html][img]http://image.wangchao.net.cn/it/1323423594100.gif[/img][/url]    dang yi ge lei han you zhuan huan yun suan fu chong zai han shu de shi hou , you shi hou hui po huai C++ yuan you gui ze , dao zhi yun suan xiao lv jiang di , zhe yi dian bu de bu zhu chong 。    shi li ru xia : // li 3 // cheng xu zuo zhe : guan ning // zhan dian :www.cndev-lab.com // suo you gao jian yun you ban quan , ru yao zhuan zai , qing wu bi wen ming chu chu he zuo zhe #include <iostream> using namespace std; class Test { public: Test(int a = 0) { cout<<this<<":"<<" zai ru gou zao han shu !"<<a<<endl; Test::a = a; } Test(Test &temp) { cout<<" zai ru kao bei gou zao han shu !"<<endl; Test::a = temp.a; } ~Test() { cout<<this<<":"<<" zai ru xi gou han shu !"<<this->a<<endl; cin.get(); } operator int()// zhuan huan yun suan fu , qu diao ze bu hui tiao yong { cout<<this<<":"<<" zai ru zhuan huan yun suan fu han shu de nei cun di zhi :"<<this->a<<endl; return Test::a; } public: int a; }; int main() { Test b=Test(99);// zhu chong zhe li cout<<"b de nei cun di zhi "<<&b<<endl; cout<<b.a<<endl; system("pause"); }    an zhao C++ dui wu ming dui xiang de yue ding ,Test b=Test(99);C++ shi hui an zhao Test b(99); lai chu li de , ke shi you yu zhuan huan yun suan fu de jia ru , dao zhi zhe yi gui lv bei po huai , xi tong hui “ cuo wu de ” ren wei ni shi yao gei dui xiang fu zhi , suo yi xi tong shou xian li yong Test(99) chuang jian yi ge lin shi dui xiang yong yu fu zhi guo cheng shi yong , ke shi qia qia xi tong you mei you shi yong zi dong ti gong de fu zhi yun suan chong zai han shu qu chu li , yin wei fa xian b dui xiang bing wei gou zao , zhuan er you bu de bu jiang kai shi yuan ben yong yu fu zhi er chuang jian de lin shi dui xiang zai ci de qiang zhuan huan wei int lei xing , ti gong gei b dui xiang jin xing gou zao , ke jian zhong jian de chuang jian lin shi dui xiang he zai ru zhuan huan yun suan fu han shu de guo cheng wan quan shi duo yu , du zhe dui ci li yao ren zhen jie du , chong fen li jie 。    yun xing jie guo ru xia tu suo shi ( yun xing guo cheng de jie shi jian tu ): [url=http://www.wangchao.net.cn/bbs/pydetail_1785399.html][img]http://image.wangchao.net.cn/it/1323423594279.gif[/img][/url]    you yu lei de zhuan huan yun suan fu yu lei de yun suan fu chong zai han shu , zai mou xie di fang shang shi yong de shi hou , you gong neng xiang si de di fang , jia ru liang zhe dou cun zai yu lei zhong , na me sui ran yun xing jie guo zheng que , dan qi yun xing guo cheng hui chu xian yi xie yi xiang bu dao de bu zhou , dao zhi cheng xu yun xing xiao lv jiang di 。    xia mian de li zi jiu shi zhe ge qing kuang , dai ma ru xia :// li 4 // cheng xu zuo zhe : guan ning // zhan dian :www.cndev-lab.com // suo you gao jian yun you ban quan , ru yao zhuan zai , qing wu bi wen ming chu chu he zuo zhe #include <iostream> using namespace std; class Test { public: Test(int a = 0) { cout<<this<<":"<<" zai ru gou zao han shu !"<<a<<endl; Test::a = a; } Test(Test &temp) { cout<<" zai ru kao bei gou zao han shu !"<<endl; Test::a = temp.a; } ~Test() { cout<<this<<":"<<" zai ru xi gou han shu !"<<this->a<<endl; cin.get(); } Test operator +(Test& temp2) { cout<<this<<""<<&temp2<<" zai ru jia yun suan fu chong zai han shu !"<<endl; Test result(this->a+temp2.a); return result; } operator int() { cout<<this<<":"<<" zai ru zhuan huan yun suan fu han shu de nei cun di zhi :"<<this->a<<endl; return Test::a; } public: int a; }; int main() { Test a(100),b(100); cout<<"a de nei cun di zhi :"<<&a<<" b de nei cun di zhi :"<<&b<<endl; Test c=a+b; cout<<"c de nei cun di zhi :"<<&c<<endl; cout<<c.a<<endl; system("pause"); }    yun xing guo cheng jian xia tu 。 [url=http://www.wangchao.net.cn/bbs/pydetail_1785399.html][img]http://image.wangchao.net.cn/it/1323423594410.gif[/img][/url]    cong tu zhong wo men ke yi qing chu de kan dao , bu bi yao de yun suan guo cheng bei zhi xing , dao zhi kai xiao zeng da , du zhe zai li jie ci li de shi hou yao ge wai xiao xin ! xian zai zong jie yi xia zhuan huan yun suan fu de you dian yu que dian :    you dian : zai bu ti gong dai you lei dui xiang shen shu de yun suan fu chong zai han shu de qing kuang xia , zhuan huan yun suan fu chong zai han shu ke yi jiang lei dui xiang zhuan huan cheng xu yao de lei xing , ran hou jin xing yun suan , zui hou zai gou zao cheng lei dui xiang , zhe yi dian he lei de yun suan fu chong zai han shu you xiang tong de gong xiao 。( li 2 jiu shi zhe zhong qing kuang )    que dian : jia ru yi ge lei zhi you zhuan huan yun suan fu chong zai han shu , er mei you zhen zheng yi yi shang yun suan fu chong zai han shu , dang yong zhuan huan yun suan fu chong zai han shu ti dai yun suan fu chong zai han shu , jin xing gong zuo de shi hou , jiu hui rang cheng xu de ke du xing jiang di , wai qu le yun suan fu cao zuo de zhen zheng han yi 。( li 2 zhong de c=a+b;// yin shi zhuan huan , jiu shi li zi , shi shi shang a+b de zuo yong zhi shi dui fan hui de zheng xing shu ju jin xing le jia yun suan , er dui xiang fu zhi de cao zuo shi xi tong yin shi de bang da jia zhuan huan cheng le c=Test(a+b)。)    zui hou wo men lai shuo yi xia , duo lu jing zhuan huan de duo yi xing wen ti , duo yi xing wen ti yi zhi shi C++ bian cheng zhong qing yi hu shi de wen ti , dan ta de que shi bu rong xiao shi , dang wen ti yin cang qi lai de shi hou ni bu hui fa jiao , yi dan chu fa ma fan jiu lai le 。    lei de zhuan huan gou zao han shu yu lei de zhuan huan yun suan fu chong zai han shu shi hu ni de 。( li 3 zhong de Test(int a = 0) shi jiang int lei xing de shu ju zhuan huan gou zao cheng Test lei dui xiang , er operator int() ze shi jiang Test lei dui xiang zhuan huan cheng int lei xing shu ju ) dan shi dang ta men shi chu xian zai liang ge bu tong de lei zhong , dui yu yi ge lei dui xiang zhuan huan lai shuo , tong shi yong you liang zhong jin si de zhuan huan tu jing de shi hou , duo yi xing de wen ti jiu bao lu chu lai , dao zhi bian yi chu cuo 。    xia li jiu shi zhe ge zhuang tai : // cheng xu zuo zhe : guan ning // zhan dian :www.cndev-lab.com // suo you gao jian yun you ban quan , ru yao zhuan zai , qing wu bi wen ming chu chu he zuo zhe #include <iostream> using namespace std; class B; class A { public: A(B &);// zhuan huan gou zao han shu , ta de zuo yong shi yong B lei dui xiang gou zao A lei dui xiang void Edita(int temp) { A::a=temp; } public: int a; }; class B { public: B(int a=0) { B::a=a; } int Ra() { return B::a; } operator A()// zhuan huan yun suan fu chong zai han shu , ta de zuo yong ze shi jiang B lei dui xiang zhuan huan cheng A lei dui xiang { return *this; } PRotected: int a; }; A::A(B &temp) { cout<<this<<""<<&temp<<endl; A::a=temp.Ra(); } void tp(A temp) { } int main() { B BT(100); A at=A(bt); //tp(bt);// cuo wu , duo yi xing wen ti , xi tong bu zhi dao ru he xuan ze , shi xuan ze A(B &) zhuan hua gou zao hao ne ? huan shi xuan ze B::operator A() jin xing zhuan huan hao ne ? tp(A::A(bt));// xian shi de chu li ke yi xiao chu duo yi xing wen ti system("pause"); }    dai ma zhong de A at=A(bt); yun xing zheng chang , yin wei xi tong fa xian dui xiang at huan wei gou zao , suo yi you xian xuan qu le A lei de zhuan huan gou zao han shu chu li le , mei you chan sheng er yi xing wen ti 。    dan shi dai ma zhong de tp(bt); bian yi cuo wu , zhe shi yin wei han shu tp de shen shu yao qiu de shi yi ge A lei dui xiang , er wo men gei ta de ze shi yi ge B lei dui xiang , er zai A lei yu B lei zhong dou you yi ge lei si de cao zuo , ke yi jiang B lei dui xiang zhuan huan cheng A lei dui xiang , xi tong bu zhi dao shi xuan qu A lei de zhuan huan gou zao han shu jin xing gou zao chu li , huan shi xuan ze B lei zhong de zhuan huan yun suan fu hao chong zai han shu chu li , xi tong ju jue cong ta men liang ge zhong xuan yi ge , suo yi bian yi cuo wu 。    wo men xiu gai tp(bt) wei tp(A::A(bt)); bian yi zheng chang , yin wei wo men xian shi de ming que de gao su xi tong ying gai shi yong A lei de zhuan huan gou zao han shu chu li , suo yi , xian shi de gao su ji suan ji ying gai ru he chu li shu ju , tong chang ke yi jie jue duo yi xing wen ti 。
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
赏心悦目的模特儿(9)
赏心悦目的模特儿(8)
赏心悦目的模特儿(7)
赏心悦目的模特儿(6)
周六一日游--绿野翠蜂场(一)
骆驼峰
下一站上环
杂乱的几张Danang
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有