很可惜的不論是Basic programming class or Advanced class 都沒有深入地去了解怎麼去使用這項function
這裡筆記的是based on C++ programming
從美國回來以後總算是開始工作了
注意到了將template實用的例子
趁這個機會好好整理一下這方面的概念,以往寫一些練習其實都沒什麼用到這個func,所以概念還真挺容易模糊掉的呢...
[開始]
Template 中譯聽說是樣板
詳情可以參考石頭閒語的C++ Template 筆記
我覺得programming這東西很多時候還是以英文來闡述比較容易了解...
在此就引述一下重點字句
It allows a programmer to reuse existing code for new purpose. In some sense, templates ensure that you don't have to continually "reinvent the wheel." -- from Data Structures and other Objects
其實這兩句話已經講掉template重點的一半了吧
//由於今晚找eBook找得很不爽....
//明天又要開始上班了..
//剩下的case study改天再續......
//有些教科書真的是買得起就該用買的阿....><
接下來就是來面對template的使用方法和簡單的case study
template一般來說可以分成兩類去想
一種是function template, another one is class template
and yes, template 前面擺著什麼,就代表你是要去做誰的輪子
在學program的時候,大部分的人都是從function到class吧
因此就想想function的部分吧
Function -> if a > 20, then c=a*12-b; otherwise c=0
我們會寫...
int Reward(int a, int b){
if (a>20)
return (a*12-b);
else
return 0;
}
那麼今天a,b很可能有多種型態出現
maybe double, maybe float
有可能有不同方向的運用(linked list, pointer..),但是都需要經過這一步
這時就template it
template當然你也可以把code都粘在一起item Reward(item a, item b){ if (a>20) return (a*12-b); else return 0; }
template只是(我覺得)很難讀罷了item Reward(item a, item b){ if (a>20) return (a*12-b); else return 0; }
OK, class function改天再續!
乖孩子要來睡覺了~~~
沒有留言:
張貼留言