作者Carbontube (碳管)
看板C_and_CPP
标题Re: [问题] 请问函式的引数若为另一函式,是否就不 …
时间Thu May 28 22:49:27 2009
※ 引述《littleshan (我要加入剑道社!)》之铭言:
这个问题没有快速又简单的解法。最简单的解法是 Mul() 和 transpose()
都回传 Matrix (传值),虽然会浪费多余的时间去复制暂时变数,但不会
造成 memory leak 或 double free 的情况。如果需要良好的效能,可能
就需要搬出 expression template 来用了。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.121.116.63
1F:→ james732:原来如此 受教了 05/28 10:23
2F:推 dcleft:推,传值应会比传vector好一些 05/28 12:06
3F:推 dcleft:不过请问一下 "回传 Matrix (传值)" 是指传double[][] ? 05/28 14:14
4F:→ dcleft:还是传什麽? 05/28 14:15
5F:→ mantour:写成一个class,然後把delete写在destructor内 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)