Template functions in C++? Maybe not the correct term -


i not sure if using right term curious if there more efficient way of doing things. have file loader deals numerous fragments (about 30 in total). class littered with:

void fragment_03(char* location, int frag_num); void fragment_04(char* location, int frag_num); void fragment_05(char* location, int frag_num); void fragment_06(char* location, int frag_num); 

...and forth. there way better way declare these functions in more generic way rather writing out 30 different function declarations?

thanks!

i'm not sure if want do, but:

you have declare , define of functions separately, can store function pointers in array.

typedef void (fragment_function) (char* location, int frag_num);  frag_function fragment_0, fragment_1, fragment_2; //define functions in cpp file  fragment_function *fragment [] = {     fragment_0,     fragment_1,     fragment_2 }; 

then define them this:

void fragment_0(char* location, int frag_num) { /**your definition here*/ } 

so can called index this:

for(int i=0; i<3; i++) {     fragment[i](frag_location[i], frag_num[i]); } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -