Re: [問題] 請問函式的引數若為另一函式,是否就不 …
※ 引述《littleshan (我要加入劍道社!)》之銘言:
這個問題沒有快速又簡單的解法。最簡單的解法是 Mul() 和 transpose()
都回傳 Matrix (傳值),雖然會浪費多餘的時間去複製暫時變數,但不會
造成 memory leak 或 double free 的情況。如果需要良好的效能,可能
就需要搬出 expression template 來用了。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.121.116.63
→
05/28 10:23,
05/28 10:23
推
05/28 12:06,
05/28 12:06
推
05/28 14:14,
05/28 14:14
→
05/28 14:15,
05/28 14:15
→
05/28 20:50,
05/28 20:50
我想請問大大,這matrix class實做是要怎樣才會自己free呢?
我想成這樣:
typedef class Matrix {
public :
int n, m; // size of column and row
double **element;
Matrix (int n=1, int m =1)
{/*allocate ememory of element */ } ;
~Matrix()
{/*free memory of element*/};
mul(Matrix B);
operator+(Matrix B);
:
:
} matrix;
/transpose is not a member function of class Matrix/
matrix transpose(matrix A)
若是這樣想不出來那裡建解構啊。。。
還請大大詳細解釋 謝謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.167.74.111
※ 編輯: Carbontube 來自: 218.167.74.111 (05/28 22:52)
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 3 之 4 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章