creating a c function at compile or runtime, is this code possible?

A

alexl

hi,

is this possible? should print "it worked.."

if so, what do I do in my "cplusplusbind" function?

typedef void(*ptf)();

class Hello {

void caller(){
ptf =cplusplusbind(this, m_callback);
..
call_fun_indirectly(ptf);
}

void m_callback () {
cout << "it worked!\n";
}

};

int main(int argc, char* argv[])
{
Hello h;
h.caller();
return 0;
}

ptf cplusplusbind (class T, T::*) {

return (/* do magic */ );
}
 
A

alexl

Thanks for your reply. Is there any workaround? I think what I am
looking for is a "nested function" which C++ doesn't officially
support. Could my "cplusplusbind" function contain some inline assembly
language code, that would:

1. create a pointer to a function of type void fun ()
2. allocate memory for it
3. populate memory so newly created function does what I want
4. return pointer to said function

thx, -Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top