review of c++

1.

const rational operator*(const rational& lhs,const rational& rhs)
  {
    return rational(lhs.numerator() * rhs.numerator(),
    lhs.denominator() * rhs.denominator());
  }
  rational onefourth(1,4);
  rational result;
  result = onefourth * 2; // 工作良好
  result = 2 * onefourth; // 万岁,它也工作了!

We do not need to use friend function, it would bring more troubles than help to you.

In terms of friend function:

if this operator becomes String's member function, it should be this shape: Sting>>cin;

thus, we can only use friend function here.

istream& operator>>(istream& input,string& string)
  {
    delete [] string.data;
    read from input into some memory,and make string.data
    point to it
    return input;
  }
ostream& operator<<(ostream& output,const string& string)
  {
    return output << string.data;
  }
const int ival = 1024;
      const int &refVal = ival;      // ok: both reference and object are const
      int &ref2 = ival;              // error: non const reference to a const object
  1. new and delete must appear in pair

  2. use new to allocate memory.

the most useful place we can utilize it: dynamic array

(caveat: we cannot use sizeof() to figure out the number of elements. Only can we program by ourselves to track the number )

reference:

http://baike.baidu.com/view/534170.htm

=========================================================

Rome wasn't built in a day.

Finished the basic review of the fundament of c++.

Written out npv function.

Need to make a detailed plan of buliding the system.

(c++, python, excel, sas...) only these can be involved in.

That's to say I have to adjourn my fucking web development.

really wish to find several partners in HKUST.
原文链接: https://www.cnblogs.com/surgod/archive/2012/09/21/2697509.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/63370

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 上午10:55
下一篇 2023年2月9日 上午10:56

相关推荐