If I would like to support the retrieval of few types from a database query in C++ I could create a method definition based on templates like
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";
}
I know that there is no real counterpart of templates in objective-c, so what what would you use to support few return values rather than implementing this like
- (type1) getType1FromCol: (int) col;
- (type2) getType2FromCol: (int) col;
- (type3) getType3FromCol: (int) col;
Thanks in advance!
You can always use Objective-C++ if you want to mix the languages, or if you find one is better suited for a particular task. Typically, you would compile as ObjC++ by changing the file extension to
.mm.For an ObjC interface, you could consider a simple wrapper interface like this, which uses your existing program:
You could approach it like this: