lundi 22 novembre 2021

Define macro that can accept both string and void parameter in c++

I would like to design a #define macro in C++ that can allow to print the value passed as parameter and a void value must be valid too. The idea Is as following snippet:

#define FOO(x) std::cout << x << std::endl;

And this must be used like this without errors:

FOO()              // empty string
FOO(1)             // 1
FOO("Hello!")      // Hello!
FOO("1+2="<<(1+2)) // 1+2=3

Some idea how to implement this? Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire