Add examples for void type in cpp (#4331) - #1
AdrianWeaver wants to merge 4 commits into
Conversation
Adding examples to cpp void page to comply with the description made in the above text.
Fixes #4331
colin-home
left a comment
There was a problem hiding this comment.
@AdrianWeaver Thanks for proposing an update and taking the initiative to implement it. I've made some suggestions, along with the rationale for them, in comments below.
| { | ||
| std::cout << num << std::endl; | ||
| } | ||
|
|
There was a problem hiding this comment.
We want our sample to include everything needed to compile the code, so in this case, it would need something like the following at the beginning:
// void.cpp
#include <iostream>
using namespace std;Unfortunately, adding this much machinery has the downside of distracting from the simplicity of the sample. If we can avoid dragging in the library, we should. Something like the following captures this idea:
// void.cpp
void return_nothing()
{
// A void function doesn't return a value.
}| void *pv; // okay | ||
| int *pint; int i; | ||
| int main() { | ||
| int main(void) |
There was a problem hiding this comment.
I don't recommend this change. We should comment in the remarks that the use of void to denote an empty parameter list is a holdover from C and isn't recommended for C++ code. For more information, see C++ Core Guidelines NL.25: Don't use void as an argument type.
Adding examples to cpp void page to comply with the description made in the above text.
Also fixing bracket to comply with code norm given as example in guidelines.
Fixes #4331