c++ - Template function for collection based on member -


i have following structures

struct obj {   int a;   int b; }; class objcollection {    map<int,obj> collmap;  public:    string getcsva();    string getcsvb(); }; 

getcsva returns csv of a values in objects of collmap. getcsvb returns same b values.

is there way can template function? reason becomes complicated me cannot pass address of member want generate csv for, outside class ie client code. there way this? note: can not use c++11.

this looks need function parameter getcsv rather templates:

declare function string getcsv(int (*selectmember)(obj)). furthermore use selectmember([...]) wherever have used [...].a in getcsva.

now can call getcsv providing method returning right field of obj, example:

int selecta(obj o) {     return o.a; } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -