[問題] 請問數學函式包成class,用static好嗎?

看板C_and_CPP (C/C++)作者 (碳管)時間16年前 (2009/05/16 23:18), 編輯推噓1(105)
留言6則, 3人參與, 最新討論串1/1
好比有個FT class : #include <math.h> #include "mathtool.h" // mathtool是定義 complex class ,一堆operator overloading // 裡面含有 typedef double real #ifndef _FT_H #define _FT_H class FT { public: static complex *FFT(int n, complex *y); static complex *IFFT(int n, complex *f); static complex *DFT(int n, complex *y); static complex *IDFT(int n, complex *f); static complex *DFT(int n, real *y); static complex *FFT(int n, real *y ); protected: static void four1(real data[], unsigned long nn, int isign); } ; #undef real #endif class 外面要用裡面的成員做計算 /*y 是長度為n的 real number array*/ real *f = FT::DFT(n,y); : : 不需要先new一個FT,用範圍運算子::即可 那請問設為static 與設為一般member在最計算時有差嗎? 速度/記憶體是否有所不同? 我是完全不知道別人怎包裝這類function的。 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.216.81.152 ※ 編輯: Carbontube 來自: 61.216.81.152 (05/16 23:22)

05/17 06:11, , 1F
應該是只差在有沒有this指標吧 個人淺見..
05/17 06:11, 1F

05/17 10:28, , 2F
static member function 根本不會傳 this pointer
05/17 10:28, 2F

05/17 10:28, , 3F
它的行為就和一般的 function 一樣,呼叫方式不同罷了
05/17 10:28, 3F

05/17 20:59, , 4F
看來你是以前寫 Java/C# 之類?一般 C++ 中很少會這樣
05/17 20:59, 4F

05/17 21:00, , 5F
包裝這類 util function. 通常當是普通 function, 最多
05/17 21:00, 5F

05/17 21:00, , 6F
放在某個 namespace 就好了
05/17 21:00, 6F
文章代碼(AID): #1A3japlO (C_and_CPP)
文章代碼(AID): #1A3japlO (C_and_CPP)