what does the void keyword do?

Hi everyone, I'm new to C++ programming, I'm sure I'll be asking many, many, MANY questions regarding this language, and would really appreciate your support!

Anyway, here's my first question - what is the void keyword meant for? I see it used usually as an immediate subsequent line after a string of code typed, for instance like this snippet -

int getScreenWidth() { return this->p_screenwidth; }
void setScreenWidth(int value) { this->p_screenwidth = value; }

Why is void in this code structure? Also a second question - what does "this->" mean?
void literally means nothing. It is usually used as a function or method return type, when the function isn't supposed to return anything. In the second method you typed out, with the void keyword, it is setting a value, and nothing needs to be returned. The first one has int, because it is returning an int, (specifically, the screen width).

this-> refers to the calling object. For the following example, I will assume the methods you posted are part of a screen class with an int p_screenwidth variable :
1
2
3
 screen example;
example.setScreenWidth(12); //when it calls the method, "this->" is the same as "example"
//"this->" is not explicitly necessary in this case 
Topic archived. No new replies allowed.