如果我想支持從在C數據庫查詢幾種類型的檢索++我可以創建基於模板的方法定義,就像C++ - 更換模板的目標C
template<typename T>
T getDBValue(int col){
throw "not implemented";
}
template<>
int getDBValue<int>(int col){
return 43;
}
template<>
char* getDBValue<char*>(int col){
return "foo";
}
我知道有沒有在Objective-C的模板真正對手,所以有什麼你會用它來支持一些返回值,而不是提前實現這個像
- (type1) getType1FromCol: (int) col;
- (type2) getType2FromCol: (int) col;
- (type3) getType3FromCol: (int) col;
謝謝!