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

Chinaunix

標(biāo)題: 函數(shù)重載求解 [打印本頁]

作者: ANONYMOUS419    時(shí)間: 2015-04-28 07:05
標(biāo)題: 函數(shù)重載求解
本帖最后由 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 ==========

作者: hellioncu    時(shí)間: 2015-04-28 08:05
左邊你加  int() 干啥?
作者: zsszss0000    時(shí)間: 2015-04-28 08:51
這個(gè)是什么編輯器,效果挺好的啊
作者: hellioncu    時(shí)間: 2015-04-28 09:27
zsszss0000 發(fā)表于 2015-04-28 08:51
這個(gè)是什么編輯器,效果挺好的啊


看最后的輸出,應(yīng)該是VS,修改了缺省的配色
作者: cokeboL    時(shí)間: 2015-04-28 09:29
回復(fù) 4# hellioncu


    也有點(diǎn)像sublime
作者: shuxiaohua1989    時(shí)間: 2015-04-28 10:38
你這開頭 一看就有錯(cuò)誤。
Complex & Complex:perator%=(const Complex & c2)
{
        int(real_) %= int(c2.real_);
        int(imag_) %= int(c2.imag_);
        return *this;
}
強(qiáng)制類型轉(zhuǎn)換后是不能作為左值的。實(shí)際上強(qiáng)制類型轉(zhuǎn)換你可以理解為:一個(gè)常量(你需要的類型),這個(gè)常量的值為原變量的值。當(dāng)然編譯器具體是怎么做的,你去學(xué)習(xí)相關(guān)的知識(shí)。
按照你的本意,代碼應(yīng)該這樣改:
Complex & Complex:perator%=(const Complex & c2)
{
        real_=int(real_)% int(c2.real_);
         imag_= int(imag_)%int(c2.imag_);
        return *this;
}
作者: ANONYMOUS419    時(shí)間: 2015-04-28 17:56
謝謝大哥回復(fù) 6# shuxiaohua1989


   




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2