Hi, I’m currently learning both C++ and Unreal Engine from one of the many courses. I am really struggling with the C++ mainly, could anyone explain why you sometimes use void at the beginning of a line of code. Thank you.
“Void” is emptiness, nothing and it has the same meaning in C++ too.
In C++ you can find it in many cases, most usually when you declare/define a method like this:
void PrintHello() {
std::cout << "Hello world!\n";
return;
}
Methods usually return something, a value back to the program so we can use it later. But when your method does not need to return something (for example, it is only used to print out messages), then you say that this method returns Void, nothing.
Hello Buddy,
I am also very new to C++ so I may be wrong but ill give it a go from what i have learned so far.
void means nothing, no value, no data, nothing.
In certain functions we expect the code to return a value.
E.g. int function (); ( we expect this to return int: an integer)
or: bool function(); (we expect this to return a bool: a true or false)
As mentioned above, sometimes we do not need the code to return anything thus we do can use void.
I hope I am right and I wish you good luck on your learning journey.
That is correct
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.