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.