Calling function by sending char text of function name.

Hello!

Is this possible?
1
2
3
4
5
int myfunc( int a, int b, char * c )

char a = "(int)myfunc()";
char b = "(int,int,char*)"
call(a, b, ...) // Function name and return type, params 


I want to do function what registers forward what will get callback if the time is right.
Basically then i dont need to edit and add extra functions into source files.
I just have to include header and use register forward function.
If there is anything close to this it would be perfect!
Thanks!
how about a function pointer ?
Last edited on
Can you give me example?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>

// here, the function print takes a function as the second
// argument and calls it

// how is a pointer to a function taking a std::size_t(unsigned
// argument and returns nothing
void print( std::size_t times, void (*how)(std::size_t) )
{
    how( times ); // dereference through '( )'
}

void f( std::size_t N )
{
    for( std::size_t i = 0; i < N; ++i ) {
        std::cout << "Hello World\n";
    }
}

void g( std::size_t N )
{
    for( std::size_t i = 0; i < N; ++i ) {
        std::cout << "Hello ";
    }
}

int main() 
{
    print( 3, &f ); // '&' (address of) is optional
    print( 3, g );
}

Hello World
Hello World
Hello World
Hello Hello Hello


http://www.cprogramming.com/tutorial/function-pointers.

More advance code involve templates or std::function but i'm going to bed now, maybe someone else could explain what is more appropriate for your problem
Last edited on
( link says : Error 404: This page could not be found. )
Anyway, is there possible to name function name with the function.
So basically if i read name from .txt i can call that function somehow?
( link says : Error 404: This page could not be found. )

That's because the forum software appends the full-stop (.) to the URL. Remove the trailing full-stop, and it should work.

If you want to post URL's and be grammatically correct, you need to leave whitespace between the URL and the full-stop - i.e. http://www.cprogramming.com/tutorial/function-pointers .

EDIT: and after all that, the URL was wrong anyway. It's http://www.cprogramming.com/tutorial/function-pointers.html .
Last edited on
Topic archived. No new replies allowed.