3 ms·
It's best to pass a reference to specify that the argument shall not be null. Also avoid writing static functions in C++, make use of anonymous namespaces.
by Kranar 4y ago
It's best to pass a reference to specify that the argument shall not be null. Also avoid writing static functions in C++, make use of anonymous namespaces.
namespace {
int add_numbers(const Data& p) {
return p.a + p.b;
}
}
- millimeterman 4y agoAgreed, though at some point we run up against the inherent triviality of the example :P.
- vasama 4y agoThere's no reason to avoid static functions. It's just a better syntax and it's a shame it cannot be applied to class declarations as well.