Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top