can u solve this???

Hi,
1.i have a char * fileName ="myFile" and a array function pointer void (*fileptr[5])(void).

2. i have five function:
void myFile1();
void myFile2();
void myFile3();
void myFile4();
void myFile5();

3.Inside a for loop am appending char * fileName
<pseudocode>:loop for i till i =5
filename = filename+'i'
do process
and loop back

4.My problem is: instead of assignin the funct pointer as fileptr[i]=myFile1
I WANT TO USE char *filename to do so.So that in every loop i can assign a diffrent function name to the array of function pointers.

can someone suggest a way???

assign a diffrent function name to the array of function pointers

What does this mean?
fileptr[0]=filename1
fileptr[1]=filename2
fileptr[2]=filename3
fileptr[3]=filename4
.
.
since i am trying to to use the char * to generate the function name, i am unable to assogn the adres of the function to the function pointer. Can it be done??
I know what code you want to write, which you already know is illegal. I was trying to get you to explain what you wanted to do in principle.

In C++, function names are just symbols that are largely lost when the code is compiled. Functions are identified by their addresses.

yes i undesatnds that.So is there any way i can do it in for loop?
My prob is that i ll have to assign address to all function poinetr(more than 15) an in future if more function gets added then maintan is prob.So any suggestion???
How can you assign a string( char*) to the function pointer ?
yes i know i cant do it!!!!!
Is there any alternate way of doing it???
Of doing what?

All you've done is shown code that doesn't work. You haven't said what want.
dear kbw,


I have function as below


void function1(){
***
}



void function2(){
***
}


void function3(){
***
}

.
.
.
.till function20()



void (*funtptr[19])(void);

//now simple way to a assign funct pointer is


funcptr[0]=function1;
funcptr[2]=function2;
funcptr[3]=function3;
.
.
.till funcptr[19];

//This can be done but its cumbersome, Also in future
//if more function get added the rework exist.

Now wat i was intending to was in for loop like thi


char *name="function";
char assign[10];
for(i=0,i<20;i++)
{
APPEND<assign=name+(i+1)> //pseudo code eg. 'assign' now contain function1
functptr[i]=name;
RESET<assign>

}


//I know th abov code does not work but i would like to it in loop
//rather then assigning one by one...

Hope i am clear this time:-)
Ok, I got it.

As you already know, you're current approach isn't going to cut it. But there may be ways to do this. But it all depends on what exactly these functions are, where they come from and how they're used. In the end, the functions and the list they go into must be encapsulated by something.

If your functions lived in seperate DLLs/Shared Libraries, the app could scan some directory for Modules that exported a function with a fixed name. If it finds it, it adds its address to your list of functions.

Or if the actuall functions were a method in a class, you build a class hierarchy with all your functions, and make each class register itself into the list on construction.

There's a variety of ways of automating this, but it all depends on what you're doing. And also, it may be simpler to just add them to the list yourelf.
Topic archived. No new replies allowed.