blue
blue

Reputation: 2793

Is it possible to write a C++ function that stringizes?

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.

Upvotes: 0

Views: 99

Answers (1)

Captain Obvlious
Captain Obvlious

Reputation: 20063

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.

Upvotes: 4

Related Questions