'C++ functions declaration with macros
I am asking about a way to improve code readability
I was able to make a macro like this for a small library I'm making
#define fun(name, arg1, arg2) void name(int arg1, int arg2)
NOTE: int is an existent class, but I replace it with int so anyone can run it
This would allow me to use this code to create a function:
fun(testFunction, x, y) {
// do stuff
std::cout << x << y << std::endl;
}
and then in my main:
int main() {
testFunction(1, 2);
return 0;
}
This works great (at least in Visual Studio, haven't tested in GCC but I think it works there too).
Is it possible to make a macro that would be like:
#define fun name(arg1, arg2) void name(int arg1, int arg2)
so a macro that would allow me to declare a function like:
fun testFunction(x, y) {
// do stuff
}
The actual thing I am asking if is there a way to make a macro that allows me to do this (for example)
CustomClassTemplate doStuff(CustomClass& arg1, CustomClassTemplate arg2, Library::Binary::Binary bin) {
// do stuff
return CustomClassTemplate(/*blah, blah, blah*/);
}
to this:
fun doStuff(arg1, arg2, bin) {
// do stuff
return CustomClassTemplate(/* blah blah blah*/);
}
you can create an empty class for each argument
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
