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 -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -