亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1611 | 回復(fù): 6
打印 上一主題 下一主題

[C++] 函數(shù)重載求解 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2015-04-28 07:05 |只看該作者 |倒序瀏覽
本帖最后由 ANONYMOUS419 于 2015-04-28 07:16 編輯
  1. #pragma once
  2. class Complex
  3. {
  4.         double real_, imag_;
  5. public:
  6.         Complex();
  7.         Complex(double, double);
  8.         ~Complex();
  9.         Complex & operator+=(const Complex &);
  10.         Complex & operator-=(const Complex &);
  11.         Complex & operator*=(const Complex &);
  12.         Complex & operator/=(const Complex &);
  13.         Complex & operator%=(const Complex &c2);
  14.         Complex & operator^=(const Complex &);
  15.         Complex & operator&=(const Complex &);
  16.         Complex & operator|=(const Complex &);
  17.         Complex & operator=(const Complex &);
  18.         bool operator>=(const Complex &);
  19.         bool operator<=(const Complex &);
  20.         bool operator==(const Complex &);
  21.         bool operator<(const Complex &);
  22.         bool operator>(const Complex &);
  23.         bool operator!=(const Complex &);
  24.         Complex & operator++();
  25.         Complex & operator--();
  26.         Complex operator++(int);
  27.         Complex operator--(int);
  28. };

  29. #include "Complex.h"



  30. Complex::Complex()
  31. {
  32.         real_ = imag_ = 0;
  33. }

  34. Complex::Complex(double r, double i):real_(r),imag_(i)
  35. {

  36. }

  37. Complex::~Complex()
  38. {
  39. }

  40. Complex & Complex::operator+=(const Complex & c2)
  41. {
  42.         real_ += c2.real_;
  43.         imag_ += c2.imag_;
  44.         return *this;
  45. }

  46. Complex & Complex::operator-=(const Complex & c2)
  47. {
  48.         real_ -= c2.real_;
  49.         imag_ -= c2.imag_;
  50.         return *this;
  51. }

  52. Complex & Complex::operator*=(const Complex & c2)
  53. {
  54.         real_ *= c2.real_;
  55.         imag_ *= c2.imag_;
  56.         return *this;
  57. }

  58. Complex & Complex::operator/=(const Complex & c2)
  59. {
  60.         if (c2.real_&&c2.imag_)
  61.         {
  62.                 real_ /= c2.real_;
  63.                 imag_ /= c2.imag_;        
  64.         }

  65.         return *this;
  66. }

  67. Complex & Complex::operator%=(const Complex & c2)
  68. {
  69.         int(real_) %= int(c2.real_);
  70.         int(imag_) %= int(c2.imag_);
  71.         return *this;
  72. }

  73. Complex & Complex::operator^=(const Complex &)
  74. {
  75.         // TODO: insert return statement here
  76. }

  77. Complex & Complex::operator&=(const Complex &)
  78. {
  79.         // TODO: insert return statement here
  80. }

  81. Complex & Complex::operator|=(const Complex &)
  82. {
  83.         // TODO: insert return statement here
  84. }

  85. Complex & Complex::operator=(const Complex &)
  86. {
  87.         // TODO: insert return statement here
  88. }

  89. bool Complex::operator>=(const Complex &)
  90. {
  91.         return false;
  92. }

  93. bool Complex::operator<=(const Complex &)
  94. {
  95.         return false;
  96. }

  97. bool Complex::operator==(const Complex &)
  98. {
  99.         return false;
  100. }

  101. bool Complex::operator<(const Complex &)
  102. {
  103.         return false;
  104. }

  105. bool Complex::operator>(const Complex &)
  106. {
  107.         return false;
  108. }

  109. bool Complex::operator!=(const Complex &)
  110. {
  111.         return false;
  112. }

  113. Complex & Complex::operator++()
  114. {
  115.         // TODO: insert return statement here
  116. }

  117. Complex & Complex::operator--()
  118. {
  119.         // TODO: insert return statement here
  120. }

  121. Complex Complex::operator++(int)
  122. {
  123.         return Complex();
  124. }

  125. Complex Complex::operator--(int)
  126. {
  127.         return Complex();
  128. }

復(fù)制代碼
1>------ Rebuild All started: Project: HomeWork2, Configuration: Debug Win32 ------
1>  Source.cpp
1>  Complex.cpp
1>e:\c++語法與數(shù)據(jù)結(jié)構(gòu)\c++語法與數(shù)據(jù)結(jié)構(gòu)第8天\homework2\homework2\complex.cpp(53): error C2106: '%=': left operand must be l-value
1>e:\c++語法與數(shù)據(jù)結(jié)構(gòu)\c++語法與數(shù)據(jù)結(jié)構(gòu)第8天\homework2\homework2\complex.cpp(54): error C2106: '%=': left operand must be l-value
1>  Generating Code...
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

論壇徽章:
324
射手座
日期:2013-08-23 12:04:38射手座
日期:2013-08-23 16:18:12未羊
日期:2013-08-30 14:33:15水瓶座
日期:2013-09-02 16:44:31摩羯座
日期:2013-09-25 09:33:52雙子座
日期:2013-09-26 12:21:10金牛座
日期:2013-10-14 09:08:49申猴
日期:2013-10-16 13:09:43子鼠
日期:2013-10-17 23:23:19射手座
日期:2013-10-18 13:00:27金牛座
日期:2013-10-18 15:47:57午馬
日期:2013-10-18 21:43:38
2 [報告]
發(fā)表于 2015-04-28 08:05 |只看該作者
左邊你加  int() 干啥?

求職 : 機(jī)器學(xué)習(xí)
論壇徽章:
79
2015年亞洲杯紀(jì)念徽章
日期:2015-05-06 19:18:572015七夕節(jié)徽章
日期:2015-08-21 11:06:172015亞冠之阿爾納斯?fàn)?日期:2015-09-07 09:30:232015亞冠之薩濟(jì)拖拉機(jī)
日期:2015-10-21 08:26:3915-16賽季CBA聯(lián)賽之浙江
日期:2015-12-30 09:59:1815-16賽季CBA聯(lián)賽之浙江
日期:2016-01-10 12:35:21技術(shù)圖書徽章
日期:2016-01-15 11:07:2015-16賽季CBA聯(lián)賽之新疆
日期:2016-02-24 13:46:0215-16賽季CBA聯(lián)賽之吉林
日期:2016-06-26 01:07:172015-2016NBA季后賽紀(jì)念章
日期:2016-06-28 17:44:45黑曼巴
日期:2016-06-28 17:44:4515-16賽季CBA聯(lián)賽之浙江
日期:2017-07-18 13:41:54
3 [報告]
發(fā)表于 2015-04-28 08:51 |只看該作者
這個是什么編輯器,效果挺好的啊

論壇徽章:
324
射手座
日期:2013-08-23 12:04:38射手座
日期:2013-08-23 16:18:12未羊
日期:2013-08-30 14:33:15水瓶座
日期:2013-09-02 16:44:31摩羯座
日期:2013-09-25 09:33:52雙子座
日期:2013-09-26 12:21:10金牛座
日期:2013-10-14 09:08:49申猴
日期:2013-10-16 13:09:43子鼠
日期:2013-10-17 23:23:19射手座
日期:2013-10-18 13:00:27金牛座
日期:2013-10-18 15:47:57午馬
日期:2013-10-18 21:43:38
4 [報告]
發(fā)表于 2015-04-28 09:27 |只看該作者
zsszss0000 發(fā)表于 2015-04-28 08:51
這個是什么編輯器,效果挺好的啊


看最后的輸出,應(yīng)該是VS,修改了缺省的配色

論壇徽章:
36
子鼠
日期:2013-08-28 22:23:29黃金圣斗士
日期:2015-12-01 11:37:51程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-14 06:20:00CU十四周年紀(jì)念徽章
日期:2015-12-22 16:50:40IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-01-25 06:20:0015-16賽季CBA聯(lián)賽之深圳
日期:2016-01-27 10:31:172016猴年福章徽章
日期:2016-02-18 15:30:3415-16賽季CBA聯(lián)賽之福建
日期:2016-04-07 11:25:2215-16賽季CBA聯(lián)賽之青島
日期:2016-04-29 18:02:5915-16賽季CBA聯(lián)賽之北控
日期:2016-06-20 17:38:50技術(shù)圖書徽章
日期:2016-07-19 13:54:03程序設(shè)計版塊每日發(fā)帖之星
日期:2016-08-21 06:20:00
5 [報告]
發(fā)表于 2015-04-28 09:29 |只看該作者
回復(fù) 4# hellioncu


    也有點像sublime

論壇徽章:
0
6 [報告]
發(fā)表于 2015-04-28 10:38 |只看該作者
你這開頭 一看就有錯誤。
Complex & Complex:perator%=(const Complex & c2)
{
        int(real_) %= int(c2.real_);
        int(imag_) %= int(c2.imag_);
        return *this;
}
強(qiáng)制類型轉(zhuǎn)換后是不能作為左值的。實際上強(qiáng)制類型轉(zhuǎn)換你可以理解為:一個常量(你需要的類型),這個常量的值為原變量的值。當(dāng)然編譯器具體是怎么做的,你去學(xué)習(xí)相關(guān)的知識。
按照你的本意,代碼應(yīng)該這樣改:
Complex & Complex:perator%=(const Complex & c2)
{
        real_=int(real_)% int(c2.real_);
         imag_= int(imag_)%int(c2.imag_);
        return *this;
}

論壇徽章:
0
7 [報告]
發(fā)表于 2015-04-28 17:56 |只看該作者
謝謝大哥回復(fù) 6# shuxiaohua1989


   
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP