Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting the name of the invoked function

when using either the '.', '->' or '->*' operators is there any way of getting the name of the function invoked (or the name of the variable in the case of '->*' and everything goes.

EDIT: Just to clarify I'm not talking about reflection but more something in the line of 'function' basically I want to create an overload of an operator (preferrably one of the three mentioned) which is aware of the right side of the operator

What I'm trying to accomplish is basically a compile time transformation of

obj->Function(a,b);

to

obj->Map("Function")(a,b); //Where Map(string) returns a function pointer

EDIT: Just to further clarify, The requirement is that the code will have to look like one of these three

obj.SomeMethod(args);
obj->SomeMethod(args);
obj->*SomeMethod(args);

any solution that fits that is acceptable as long as SomeMethod can be any valid identifier (I.e. any thing that can be used as a function name) and the solution will have to use SomeMethod as a lookup in a Map. The Map part is already implemented it's only the reinterpretation of what looks like a method call I seeking a solution to.

if that (as I'm affraid) can't be done then any solution with a new "operator" syntax will be accepted. Such as obj __ SomeMethod(args); as long as the lookup is based on the RHS of the "operator"

like image 506
Rune FS Avatar asked Jan 01 '26 22:01

Rune FS


2 Answers

As far as I know, no. C++ does not support any form of reflection, so in order to get this kind of information you have to design your own tools and tricks.

like image 115
Stefano Borini Avatar answered Jan 03 '26 11:01

Stefano Borini


C++ doesn't have any kind of reflection. The names of the functions are gone by the time that your executable is running. The only way to do it is to pass them in.

If you were planning to do something based on the method name, perhaps you just need virtual methods or overloading so that the right code is called.

like image 36
Lou Franco Avatar answered Jan 03 '26 11:01

Lou Franco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!