سؤال

How would you go if you had to write a proper C++ function that does the same as the operator '#' in macros?

It would be useful if it were possible to do it at runtime.

هل كانت مفيدة؟

المحلول

You can't. What you are basically asking for is this...

void function(int someargname)
{
    std::cout << #someargname << std::endl;
}

int main()
{
    function(3);
    return 0;
}

And expecting to get "someargname" as the output instead of "3". The language simply does not support that syntax.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top