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

2.  new and delete must appear in pair

3.  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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值