全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:991
推到 Plurk!
推到 Facebook!

請問有關Function Pointer的書

尚未結案
willchen
初階會員


發表:64
回覆:81
積分:29
註冊:2003-05-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-06-09 09:09:37 IP:60.248.xxx.xxx 未訂閱
各位高手好,小弟最近在程式上想更上一層樓,想學學函數指標的進階用法,我查過很多本書,發現函數指標很少提到,就算提到也只有概略性的說,不知道市面上有哪本書(原文也可)有寫C的進階 我看過Primer C也是提到很少,網路上的資料也是很少,大多都只知道他的用法,但何時需要用到他,都沒有明確說明。
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-06-09 22:42:32 IP:211.76.xxx.xxx 未訂閱
willchen 您好    修改之前寫過的程式供您參考一下! 接著您可以自行修改與做進一步的測試.希望對您有幫助!    
typedef float (*fnPtr)(float , float); // 自定一個函式指標:
                                       // 傳入兩個float參數,並傳回float的結果!    float add(float x, float y)
{
  return ( x + y );
}    float sub(float x, float y)
{
  return ( x - y );
}    float mul(float x, float y)
{
  return ( x * y );
}    float div(float x, float y)
{
  return ( x / y );
}    float myPow(float x, float y)
{
  return ( pow (x, y) );
}    void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
  if ( ComboBox1->ItemIndex==-1 )
    ComboBox1->ItemIndex = 0;
}
//---------------------------------------------------------------------------
fnPtr aryFn[] = {add, sub, mul, div, myPow};    void __fastcall TForm1::btnAnswerClick(TObject *Sender)
{
  float x, y, result;
  fnPtr fn;      if ( ComboBox1->ItemIndex==-1 ) ComboBox1->ItemIndex = 0;
  fn = aryFn[ComboBox1->ItemIndex]; // get the function user specified.      x = StrToFloat(edX->Text);  // get the value x
  y = StrToFloat(edY->Text);  // get the value y
  result = fn(x, y);          // invoke function assigned dynamically      edResult->Text = result;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  fnPtr fn;
  fn = add;
  ShowMessage(fn(3,4));
}
//---------------------------------------------------------------------------
Source codes: http://delphi.ktop.com.tw/loadfile.php?TOPICID=22816148&CC=510272 RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====#####
speed
一般會員


發表:13
回覆:17
積分:6
註冊:2003-04-30

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-06-10 02:15:28 IP:218.162.xxx.xxx 未訂閱
小弟推薦一本書 Pointer on C by Kenneth A.Reek 絕對讓你對C語言指標有更清楚的了解^^
bugmans
高階會員


發表:95
回覆:322
積分:188
註冊:2003-04-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-06-10 16:50:05 IP:218.167.xxx.xxx 未訂閱
這個網站提供你參考 The Function Pointer Tutorials html版 http://www.newty.de/fpt/index.html PDF版 http://www.newty.de/fpt/zip/e_fpt.pdf
系統時間:2024-06-24 20:42:45
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!